Problem stataments in Matlab
7 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Dyuman Joshi
2022-5-19
Final answer, I have tested this code on my laptop
cd=0; %counting $
userd=[];
for i=1:size(T,1)
if isequal(char(T.Column2(i)),'$')
cd=cd+1; %number of '$' has been pressed.
userd=[userd char(T.Column1(i))];
end
end
uniqued=numel(unique(userd))
cnic=0; %counting NIC before $
usernic=[];
for j=1:size(T,1)-1
if isequal(char(T.Column2(j)),'NIC')&isequal(char(T.Column2(j+1)),'$')
cnic=cnic+1;
usernic=[usernic char(T.Column1(j))];
end
end
uniquenic=numel(unique(usernic))
0 个评论
更多回答(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-13
4 个评论
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!