Search in a column based a result from another column

1 view (last 30 days)
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

Accepted Answer

dpb
dpb on 27 Aug 2022
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 Comments
dpb
dpb on 28 Aug 2022
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 on 28 Aug 2022
Thanks a lot @dpb, I'll take in consideration to upgrade the application.

Sign in to comment.

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Products


Release

R2015a

Community Treasure Hunt

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

Start Hunting!