Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

File opening dialog box for predefined dialogs in MATLAB and how to rename them in batches

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail about the predefined dialog box in MATLAB file to open the dialog box and how to rename it in batches, the content of the article is of high quality, so the editor will share it for you to do a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Function: uigetfile. The name of this function is divided into three parts, and it is easy to understand, ui: user interface, get: get, file: file. Adding it together gives you an interface to select (get) a file.

Usage: first of all, this function only gets the file name and file path, as well as a default output. The representation with a small extension can be omitted.

Extension names should be enclosed in curly braces and separated by semicolons, such as:

{'* .jpg';'* .bmp';'* .png'}

The first return parameter is the file name (with the extension), the second is the path where the file is located (with'\'at the end, but not the uigetdir function, which will be discussed later), and the third parameter indicates which extension you have chosen.

Click 'Open' (blocked by watermark

The returned value displayed on the command line is as follows:

FName =

Cancle.png

PName =

C:\ Users\ F\ Desktop\ icons\

Index =

three

'* .png' is the third, so index is 3.

Then combined with the content said yesterday to implement: create a file open dialog box to select jpg,png,bmp images, and save all the pictures with the extension of jpg,png,bmp under the path where the file is changed, and save the number of photos: (the code is as follows, in which warning off can be ignored)

Let's talk about how to rename all files in a folder in batch.

First of all, let's talk about how I encountered this problem. The day before yesterday, when I was working on my resume, I found that I couldn't remember what I had done with genetic algorithm to optimize. Then I opened the code and found that it was wrong because I couldn't find the function file. I used the genetic algorithm toolbox of the University of Sheffield, and when I downloaded it, the extension name of all the code in it was: .M. While MATLAB is case-sensitive, the correct m file extension should be: .m. There are many functions in a toolbox. What should I do? Manual modification? Not only can you be exhausted, but you can also make you blind. So let's get down to business:

First of all, there is no renamed function in MATLAB, but there is a function called rename in the windows operating system that can rename file. So how to execute operating system commands in MATLAB: simply add an exclamation point (an exclamation point in English input state) before the command you want to execute.

Usage:! rename,OldName,NewName

Some of the files under the folder at the beginning:

A second after running the code

There are only a few lines of code, so let's explain this:

This is easy to understand, first execute dir to get all the files with the .m extension, dir returns a structure with five fields, the first field is name, and then directly struct2cell returns an array of cells with five rows, we only need the contents of the first line (the first line is the value of name). So proceed to:

All right, now all the file names to be changed have been worked out. The next step is to traverse the elements in the files

Because the code is very short, it is executed directly on the command line.

Get the first name and then execute the sentence eval, which is used to rename. Let's explain the eval line:

Eval is a function used to execute a string, for example: 3: 5 is equivalent to eval ('3: 5'), so this sentence here is equivalent to! rename,file,file (1:end-1) .m. But you can't do this directly, because! every comma after rename is treated as a string, and there is no file named''file''' or''file (1:end-1) .m' under the path, so it doesn't work.

Instead of using square brackets to concatenate these characters horizontally, file is not the character 'file', but the specific file name corresponding to file. File (1:end-1) is the string that gets the suffix M removed.

If executed individually, it should be as follows:

About the MATLAB predefined dialog box file opening dialog box and how to batch rename is how to share here, I hope the above content can be of some help to you, you can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report