how to print randomly selected column?

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

Antworten (1)

James Tursa
James Tursa am 10 Dez. 2021
Bearbeitet: James Tursa am 10 Dez. 2021

0 Stimmen

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 Kommentare

Haley Kelly
Haley Kelly am 10 Dez. 2021
it still gives me this error
'Unrecognized function or variable 'fprinf'.'
James Tursa
James Tursa am 10 Dez. 2021
Bearbeitet: James Tursa am 10 Dez. 2021
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( ).
Or simply check if it starts with a y or Y
if startsWith(random_column, 'y', 'IgnoreCase', true)

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 10 Dez. 2021

Kommentiert:

am 10 Dez. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by