how to print randomly selected column?
2 ビュー (過去 30 日間)
古いコメントを表示
this is what i have, the data is 39,18
data = readtable('playlist.xlsx');
random_column = input('Would you like to print a random column? yes, no. ', 's');
if random_column == "yes"
x = randi(size(data,1));
column = data(:,x);
fprinf(column)
elseif random_column == "no"
fprintf('thats the end')
end
0 件のコメント
回答 (1 件)
James Tursa
2021 年 12 月 10 日
編集済み: James Tursa
2021 年 12 月 10 日
Shouldn't that be size(data,2)?
Also, generally you should be using string comparison functions for the tests, not the == operator. E.g.,
isequal(random_column,'yes')
or
strcmpi(random_column,'yes')
3 件のコメント
James Tursa
2021 年 12 月 10 日
編集済み: James Tursa
2021 年 12 月 10 日
Because you have a typo. Should be fprintf, not fprinf
Also, fprintf( ) is typically used with a format string. To just print a variable you can use disp( ).
Image Analyst
2021 年 12 月 10 日
Or simply check if it starts with a y or Y
if startsWith(random_column, 'y', 'IgnoreCase', true)
参考
カテゴリ
Help Center および File Exchange で Data Import from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!