Search in a column based a result from another column
조회 수: 1 (최근 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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1109685/image.jpeg)
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
댓글 수: 0
채택된 답변
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
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).
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!