Is there a way to choose what file to open in the command window using input(prompt)?
3 ビュー (過去 30 日間)
古いコメントを表示
Simon Hammerlid
2019 年 10 月 4 日
コメント済み: Simon Hammerlid
2019 年 10 月 4 日
I am writing a script that compares the temperature of two cities, and I want to be able to switch which cities I'm comparing without having to rewrite my code. Therefore I wrote the following code:
prompt = "What is the file address to the first city?"
firstcity = input(prompt, 's')
load firstcity
To which an answer could be: Cities/Paris.txt
Which would replace:
load Cities/Paris.txt
I'm not aware of a datatype for a fileadress, and am left unsure of how i would go about solving this problem.
0 件のコメント
採用された回答
Dimitris Kalogiros
2019 年 10 月 4 日
編集済み: Dimitris Kalogiros
2019 年 10 月 4 日
disp( "What is the file address to the first city?");
[firstcity,path] = uigetfile('*.txt');
if isequal(firstcity,0)
disp('User selected Cancel');
else
disp(['User selected ', fullfile(path,firstcity)]);
load(fullfile(path,firstcity))
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!