Search in a column based a result from another column

2 次查看(过去 30 天)
Hi,
I have a script who search ina table and display a message with the number of results for each category like this:
tableData = get(handles.uitable4, 'data');
tableData = cell2table(tableData);
rezultat = tableData(:,79);
rezultat = table2cell(rezultat);
rezultat = rezultat';
disp(rezultat);
[uniqueXX,~,J] = unique(rezultat);
occ = histc(J,1:numel(uniqueXX));
occ = num2cell(occ);
occ = occ';
final = [uniqueXX; occ];
final = final';
f= figure;
uitable(f,'data',final);
The table is this:
The result is like: FIAT 1
RENAULT 2
I want is to display the result only if it meet a criteria from the first column. Only if RENAULT is AMI, not NMI Example of desired result: FIAT 1 and RENAULT 1

采纳的回答

dpb
dpb 2022-8-27
More pain when don't attach data to use, but...
tData=table(categorical({'AMI';'NMI';'AMI'}),categorical({'Fiat';'Renault';'Renault'}),'VariableNames',{'Class','Make'});
tGrpCounts=groupcounts(tData,{'Class','Make'});
>> tGrpCounts(tGrpCounts.Class=='AMI',:)
ans =
2×3 table
Class Make GroupCount
_____ _______ __________
AMI Fiat 1
AMI Renault 1
>>
  6 个评论
dpb
dpb 2022-8-28
Oh, phooey! I forget you're running a version from the dark ages, yet -- the table class wasn't supported by uitable until R2018a.
I'd urge you to update your version--so many useful features such as this have been introduced since...all the machinations you're doing to retrieve individual arrays and having issues regarding disparate types would all disappear as bad memories...
But, if it is impossible, then you'll have to either be able to convert all to one type (may, may not be practical/sensible to make everything categorical???--I don't know anything about your application data types to be able to judge) or mush everything into a cell array that can hold disparate things. The last example at <uitable> addresses displaying mixed data types without using a table directly (which still would be the ideal way to solve this if you can possibly at all upgrade).
Cristian Martin
Cristian Martin 2022-8-28
Thanks a lot @dpb, I'll take in consideration to upgrade the application.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

产品


版本

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by