Problem stataments in Matlab
이전 댓글 표시
Hi,
I would like to make a problem statement in Matalb, here are 3 columns, the 1st column is the user ID, the 2nd is (A/B) and 3rd is the combinations of $ and NIC.
(1) I wanted to count (a) how many many times $ has been pressed in total (b) count multiple $ as once pressed only by each user and total number of it.
(2) And in column 2, i wanted to check how many times the NIC has been pressed before $ pressed (so, 1st pressed: NIC, 2nd pressed: $) and count the total number of users.
I haven't used the Matalb for so long, so i would like to know how to do it...

Tim
채택된 답변
추가 답변 (3개)
Dyuman Joshi
2022년 5월 12일
편집: Dyuman Joshi
2022년 5월 13일
I'm assuming that the data in Column 1 and Column 2 is char/strings.
%T is your table
cd=0; %counting $
userd=[];
for i=1:size(T,1)
if isequal(T.Column2(i),'$')
countd=countd+1; %number of '$' has been pressed.
userd=[userd T.Column1(i)];
end
end
uniqued=numel(unique(userd));
cnic=0; %counting NIC before $
usernic=[];
for j=1:size(T,1)-1
if isequal(T.Column2(i),'NIC')&isequal(T.Column2(i+1),'$')
cnicbefd=cnicbefd+1;
usernic=[usernic T.Column1(i)];
end
end
uniquenic=numel(unique(usernic));
댓글 수: 12
ka chun yick
2022년 5월 12일
Dyuman Joshi
2022년 5월 12일
I have edited my answer
ka chun yick
2022년 5월 12일
ka chun yick
2022년 5월 12일
ka chun yick
2022년 5월 13일
Dyuman Joshi
2022년 5월 13일
Can you show what the values in T are?
ka chun yick
2022년 5월 13일
Dyuman Joshi
2022년 5월 13일
I saw that. But I don't know what is the data type. Can you post the data here so I can try it myself directly?
ka chun yick
2022년 5월 13일
Dyuman Joshi
2022년 5월 13일
편집: Dyuman Joshi
2022년 5월 13일
Okay, when you import T, what is the data type of Column 1 and 2? Char/string or categorical?
Asking because I am getting 2 different answers on based on method of importing.
ka chun yick
2022년 5월 13일
Dyuman Joshi
2022년 5월 13일
I have modified my code accordinly, please check.
ka chun yick
2022년 5월 13일
0 개 추천
댓글 수: 4
Dyuman Joshi
2022년 5월 13일
sorry, change cd=0 to countd=0.
ka chun yick
2022년 5월 14일
ka chun yick
2022년 5월 18일
Dyuman Joshi
2022년 5월 18일
This is just a data type mismatch in the if condition statement. Check what the data type in table T, then you can edit accorindingly as well.
카테고리
도움말 센터 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




