EXTRACT THE DISPLAYED COLUMN VECTORS INTO TABLE AND .CSV FILE

Hi everyone, I want to extract all the output numbers into a .csv table.
A = table2array(Output)
A(1,:) = [] %delete first row of the double column
for i = 1:20
B = A(:,i);
x = unique(B);
N = numel(x);
count = zeros(N,1);
for k = 1:N
count(k) = sum(B==x(k));
end
disp([ x(:) count ]);
end
I get 2 errors:
1) For the """"disp([ x(:) count ]);"""" I only get in the output the numbers 1 and 0 of the last column of the tabe A, it doesn't maintain the columns before.
2) How should I write the script line in order to get a table and a .csv at the end for the """count""" column vectors displayed??
Thank you a lot in advance for your help guys!!

댓글 수: 5

It would help if we had some sample content for Output
Myke Ziz
Myke Ziz 2020년 1월 2일
편집: Myke Ziz 2020년 1월 2일
Hi Robert, it is a simple table.
41 rows 20 columns
each column lead the name of a different participant (correct 1, incorrect 0)
40 rows means 40 trials
I deleted the number 1 row containing the NaN -> 40 rows in total remaining
The output appears to be correct to me. You have
for i = 1:20
%...
count = zeros(N,1);
%...
end
so you create a new count array for every iteration of the loop. The result at the end is going to be just the value you last assigned to it, reflecting the array newly created for i = 20.
Where should I insert it exactly on the script because nothing change in my count table, when I tried to insert it.
I continue to get only the results of 1 column, the last one calculated.
for i = 1:20
B = A(:,i); %check only the first column
x = unique(B);
N = numel(x);
count = zeros(N,1);
for k = 1:N
count(k) = sum(B==x(k));
end
disp([ x(:) count ]);
end
Thank you a lot!
Best
M. Z.
for i = 1:20
B = A(:,i);
x = unique(B);
N = numel(x);
for k = 1:N
count(x(k)+1, 1) = x(k);
count(x(k)+1, k+1) = sum(B==x(k));
end
end
disp(count)
This relies on the values in A being non-negative integers.

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

 채택된 답변

Walter Roberson
Walter Roberson 2020년 1월 2일
count1 = sum(A(:,1:20));
count0 = size(A,1) - count1;
count = [0 count0; 1 count1];

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

질문:

2020년 1월 2일

댓글:

2020년 1월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by