I am getting a 'Argument must contain a string' error.
조회 수: 4 (최근 30일)
이전 댓글 표시
sivalogan satchithanandamoorthy
2017년 5월 8일
댓글: sivalogan satchithanandamoorthy
2017년 5월 8일
[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
채택된 답변
Walter Roberson
2017년 5월 8일
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개)
참고 항목
카테고리
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!