필터 지우기
필터 지우기

Rename file using multiple drop downs (app designer)

조회 수: 5 (최근 30일)
Garrett Craig Porter
Garrett Craig Porter 2022년 7월 12일
답변: Garrett Craig Porter 2022년 7월 13일
I have .m code that executes an app made in App Designer. A button in the app saves a file as "TestData.csv" in a specified folder. I would like to add multiple dropdowns to the GUI with descriptions, and then a rename button that renames the file according to the selections in the drop down. The addition to the GUI would look something like this:
The goal is to have matlab locate the file named "TestData.csv" and rename it to "Description1_Description2_Description3_Description4.csv". Is this possible? Here's what I have so far. What I cant figure out is how to string together the event.Values and rename the file with the selected drop downs. Not sure if movefile is the correct command here.
function Rename_Data_Callback(app, event)
app.Description1.Value = event.Value;
app.Description2.Value = event.Value;
app.Description3.Value = event.Value;
app.Description4.Value = event.Value;
%some sort of code that creates the new name with '_' between each value
movefile C:\Users\Desktop\TestData.csv C:\Users\Desktop\NewName.csv
end
  댓글 수: 4
Garrett Craig Porter
Garrett Craig Porter 2022년 7월 12일
Thank you dpb, its working now!
Rik
Rik 2022년 7월 13일
You should post your solution as an answer. That way people with a similar question can see the solution.

댓글을 달려면 로그인하십시오.

채택된 답변

Garrett Craig Porter
Garrett Craig Porter 2022년 7월 13일
function Rename_Data_Callback(app, event) %callback for button press
app.Description1DropDown.Value;
app.Description2DropDown.Value;
app.Description3DropDown.Value;
app.Description4DropDown.Value;
TestData='C:\Users\Desktop\TestData.csv'; %location of file to be renamed
rename=strcat("C:\Users\Desktop\",app.Description1DropDown.Value,'_',app.Description2DropDown.Value,'_',app.Description3DropDown.Value,'_',app.Description4DropDown.Value,'.csv');
movefile(TestData, rename);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by