I am getting a 'Argument must contain a string' error.

[fileName,filePath] = uigetfile({'*.txt'},'Pick a file','MultiSelect','on')
pathToFile = fullfile(filePath,fileName)
x= size(pathToFile,2)
store=load(pathToFile(:,1));
prompt ='Please choose the Stress column';
stress=store(:,input(prompt));
prompt ='Please choose the strain column';
strain=store(:,input(prompt));

4 件のコメント

Stephen23
Stephen23 2017 年 5 月 8 日
@sivalogan satchithanandamoorthy: please edit your question and show the complete error message This means all of the red text. You have multiple commands, and we are not going to be able to help you much if we have to guess where the error occurs.
sivalogan satchithanandamoorthy
sivalogan satchithanandamoorthy 2017 年 5 月 8 日
編集済み: Walter Roberson 2017 年 5 月 8 日
command window
fileName =
'B736.14-RH-01.txt' 'Test_1_45.txt'
filePath =
C:\Users\Student\Desktop\Siva\
pathToFile =
'C:\Users\Student\Desktop\Siva\B736.14-RH-01.…' 'C:\Users\Student\Desktop\Siva\Test_1_45.txt'
x =
2
str =
'C:\Users\Student\Desktop\Siva\B736.14-RH-01.txt'
Error using load
Argument must contain a string.
Error in Testrun (line 16)
store=load(pathToFile);
Adam
Adam 2017 年 5 月 8 日
Where does 'str' come from?
sivalogan satchithanandamoorthy
sivalogan satchithanandamoorthy 2017 年 5 月 8 日
I want user to open multiple file. 'str' is basically a folder for one of the file.

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2017 年 5 月 8 日

0 投票

store = load(pathToFile{1});
You have multiselect on and you are selecting multiple files, so pathToFile could be a cell array of strings. pathToFile(:,1) would then be a cell array of strings. When you use multiselect, you get a row vector cell array, so pathToFile(:,1) would be a 1 x 1 cell array of strings. You cannot load() using a cell array of strings: you have to load() a character vector such as pathToFile{1}
Caution: when multiselect is on, but the user only selects a single file, the first output is a char vector; if the user selects multiple files then the first output is a cell array of strings. You should not assume that the user definitely selected multiple files, so you should protect against the possibility:
[fileName,filePath] = uigetfile({'*.txt'},'Pick a file','MultiSelect','on');
if isnumeric(fileName); disp('Cancelled!'); return; end
fileName = cellstr(fileName); %converts possible single string to cell array, leaves existing cell arrays the way they are.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeApp Building についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by