フィルターのクリア

Undefined operator '==' for input arguments of type 'cell'.

62 ビュー (過去 30 日間)
UMA RAMASAMY
UMA RAMASAMY 2019 年 6 月 26 日
コメント済み: UMA RAMASAMY 2019 年 6 月 26 日
load hospital
hospital.Properties.ObsNames(1:10)
dsMale = hospital(hospital.Sex=='Male',:);
dsMale(1:10,{'LastName','Sex'})
this above code is present in matlab documentation this work well....
where as i tried in different dataset....
[~,~, AllData] =xlsread('play.xls','Sheet1','A1:E15');
student = cell2dataset(AllData);
ds1=student(student.class=='first',:) % i need to store in another dataset student details who's class is first
i get an error...Undefined operator '==' for input arguments of type 'cell'.

採用された回答

Guillaume
Guillaume 2019 年 6 月 26 日
Use strcmp to compare a cell array of char vectors to another char vector:
ds1 = student(strcmp(student.class, 'first'), :)
  4 件のコメント
Guillaume
Guillaume 2019 年 6 月 26 日
Sure, but as said for char arrays you can't use ==, you have to use strcmp, so:
student(strcmp(student.class, 'first') & student.mark >= 80, :)
If there is only a few different values in class, you could convert it to categorical, which uses == for comparison:
student.class = categorical(student.class); %only needed once after loading the table
%...
student(student.class == 'first' & student.mark >= 80, :) %class is categorical so can use ==
Alternatively, you can compare to a string (using "" instead of ''). strings also use == for comparison.
%optional, convert cell array of char vectors to string array
%student.class = string(student.class);
student(student.class == "first" & student.mark >= 80, :) %string comparison. can use ==
UMA RAMASAMY
UMA RAMASAMY 2019 年 6 月 26 日
thank you...thank you...thank you... for your great explanation and code. it works like a charm.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by