how to print randomly selected column?

2 views (last 30 days)
Haley Kelly
Haley Kelly on 10 Dec 2021
Commented: Image Analyst on 10 Dec 2021
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);
elseif random_column == "no"
fprintf('thats the end')

Answers (1)

James Tursa
James Tursa on 10 Dec 2021
Edited: James Tursa on 10 Dec 2021
Shouldn't that be size(data,2)?
Also, generally you should be using string comparison functions for the tests, not the == operator. E.g.,
Image Analyst
Image Analyst on 10 Dec 2021
Or simply check if it starts with a y or Y
if startsWith(random_column, 'y', 'IgnoreCase', true)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!