Search in a column based a result from another column

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

 Risposta accettata

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 Commenti

Thanks dpb!
But for my 2015a, the groupcounts is not an option so I replaced with grpstats and it works great !
tableData = get(handles.uitable4, 'data');
tableData75 = tableData(:,75);
tableData79 = tableData(:,79);
tData=table(categorical(tableData75),categorical(tableData79),'VariableNames',{'Class','Name'});
tGrpCounts=grpstats(tData,{'Class','Name'});
a = tGrpCounts(tGrpCounts.Class == 'AMI',:);
b = [a.Name, a.Class, a.GroupCount];
fig= figure;
uitable(fig,'data',b);
I manage to transpose your code for my table, but I encounter an error:
Error using categorical/cat (line 56)
Can not concatenate a double array and a categorical array.
I try to display the result in a figure, can you give a tip?
A uitable can support a table as the 'Data' property; but you can't put disparate data types into a single array as you're trying to do. Use the table to load into the display table directly.
Can you tell me how to do it?
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).
Thanks a lot @dpb, I'll take in consideration to upgrade the application.

Accedi per commentare.

Più risposte (0)

Prodotti

Release

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by