Trying to request user input and then perform if elseif else end function...
5 次查看(过去 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!