Find number of row in a table.

조회 수: 17 (최근 30일)
fyza affandi
fyza affandi 2018년 12월 24일
편집: dpb 2018년 12월 25일
I have the following table
tblB =
Symbol Count
______ _____
1 25
3 8
2 7
5 7
4 6
10 3
8 2
11 1
12 1
14 1
15 1
16 1
21 1
which is based on the matrix E1 below
E1 =
1 1 4 5 1 1 3 1
1 1 2 5 1 1 1 1
3 4 1 3 5 10 5 4
4 2 3 4 5 8 4 1
1 2 12 16 1 1 3 3
1 2 10 14 1 1 1 1
1 1 10 8 2 5 3 15
5 2 1 3 2 21 1 11
How can I find the number of row for the symbol of the matrix.?
For example for E1(1,1) is from row 1 of tblB and so on....
row = [1 1 5 4 1 1 2 1......]
  댓글 수: 1
Image Analyst
Image Analyst 2018년 12월 24일
편집: Image Analyst 2018년 12월 24일
E1(1,1) is 1. So you want to find every row of tblB that has equals E1(1,1)?
Like
rowsWith1 = tblB{:, 1} == E1(1,1) | tblB{:, 2} == E1(1,1);
Please clarify. How are you getting the columns (values) in your row vector called "row" from tblB and E1(1,1)?

댓글을 달려면 로그인하십시오.

채택된 답변

dpb
dpb 2018년 12월 24일
Preliminaries...
E1 =[1 1 4 5 1 1 3 1
1 1 2 5 1 1 1 1
3 4 1 3 5 10 5 4
4 2 3 4 5 8 4 1
1 2 12 16 1 1 3 3
1 2 10 14 1 1 1 1
1 1 10 8 2 5 3 15
5 2 1 3 2 21 1 11];
u=unique(E1);
n=histc(E1(:),u);
[n,ix]=sort(n,'descend');
t=table(u(ix),n,'VariableNames',{'Symbol','Count'});
Now the magic...
>> arrayfun(@(x) find(x==t.Symbol),E1)
ans =
1 1 5 4 1 1 2 1
1 1 3 4 1 1 1 1
2 5 1 2 4 6 4 5
5 3 2 5 4 7 5 1
1 3 9 12 1 1 2 2
1 3 6 10 1 1 1 1
1 1 6 7 3 4 2 11
4 3 1 2 3 13 1 8
>>
  댓글 수: 2
fyza affandi
fyza affandi 2018년 12월 24일
Thank you so much :)
dpb
dpb 2018년 12월 24일
편집: dpb 2018년 12월 25일
No problem...glad to help. :)
BTW, be aware that the data of the table t is embedded in the anonymous function when the function is defined. Thus if the data in the table change, you must also redefine the function...that happens automagically as written but if you were to define a separate function handle first and then change the data, then the existing function handle wouldn't know anything about that new data...

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

KSSV
KSSV 2018년 12월 24일
YOu have many functions to get that information. Read about find, ismember and logical sign ==. YOu can access the whole column of table tblB using.
tblB.(1)
tblB.(2)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by