Trying to request user input and then perform if elseif else end function...
4 ビュー (過去 30 日間)
古いコメントを表示
I have a for loop which generates a figure on each loop. Based on what I see in the figure, I want my code to request a user input of either Y or N.
Then, on input of either Y or N, I would like to add a row to an output matrix, which I will ultimately write to a .csv.
The first column in each row will be the filename of the figure, and the second column, either 'yesboat' or 'notboat' depending on whether the input is Y or N.
This code isn't working AT ALL but it's what I have pulled together from the help files... if you have any suggestions to make it work, I would be very grateful.
Also, which is the best way to create an empty output for storing text info. such as this? My filenames are numbers at the moment but I would like them to be stored as text.
%create output array, table with two columns
output=[];
row=1;
prompt='Can you see boat noise? Y/N';
x=input(prompt);
if x=='Y'
%store filename in output with 'boat' in second column
output(row,1) = filename; %e.g.5103.190828112504 /variable.yymmssHHMMSS
output(row,2) = 'yesboat';
elseif x==N
%store filename in output with 'no boat' in second column
output(row,1) = filename;
output(row,2) = 'noboat';
else
disp('Input must be Y or N!')
end
row=row+1;
0 件のコメント
採用された回答
Stephen23
2019 年 8 月 29 日
"...which is the best way to create an empty output for storing text info..."
Use a cell array or a string array, e.g.:
out = cell(N,2);
for row = 1:N
prompt='Can you see boat noise? Y/N';
x = input(prompt,'s'); % need 's'
switch upper(x)
case 'Y'
out{row,1} = filename;
out{row,2} = 'yesboat';
case 'N'
out{row,1} = filename;
out{row,2} = 'noboat';
otherwise
...
end
2 件のコメント
Stephen23
2019 年 8 月 29 日
"...any ideas why this '8___ ' appears?"
It looks like MATLAB might be in some debugging mode. Do you have any breakpoints set?
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Type Identification についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!