필터 지우기
필터 지우기

how to print randomly selected column?

조회 수: 1 (최근 30일)
Haley Kelly
Haley Kelly 2021년 12월 10일
댓글: Image Analyst 2021년 12월 10일
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

답변 (1개)

James Tursa
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
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
Image Analyst 2021년 12월 10일
Or simply check if it starts with a y or Y
if startsWith(random_column, 'y', 'IgnoreCase', true)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by