filter certain column in an array

I have data array as following, the first 2 lines are not shown in the csv file.
----Student 1---- ----Student 2---- ----Student 3---- ----Student 4---- ----Student 5---- %not shown in csv%
Eng. Math Science Eng. Math Science Eng. Math Science Eng. Math Science Eng. Math Science %not shown in csv%
50 20 100 80 80 60 80 50 60 90 100 20 50 100 100
80 30 60 50 60 70 80 30 70 50 0 90 70 100 90
60 70 80 30 90 40 100 90 60 10 80 40 80 40 60
I have created a table to allow the user to filter some students out of this table. For example, if student 4 is selected. StudentKept = [1 2 3 5]. Then may I know how to re-construct the csv file with only StudentKept??
Current coding:
StudentKept=find([data{:,2}]==0);
for m = studentKept
dataArrayFiltered=[dataArrayAll(studentKept,1)];
end

댓글 수: 2

have you checked the option csvwrite.
Adithya Addanki
Adithya Addanki 2016년 1월 14일
Hi,
There is no direct way of doing this through "csvwrite" or "xlswrite". I think you will be able to achieve it in a programmatic way.
You may need to extract the columns that are not being selected(may be a flag to see if it is selected or not? or indexing actually through all the data and selecting the unfiltered data based on row and column indexes).
Thank you,
Adithya

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

답변 (1개)

Guillaume
Guillaume 2016년 1월 14일

0 개 추천

The first thing to do is to get rid of the flat format of your file, which is not helpful for manipulating data. Reshaping the data so that students are the third dimension makes it easy to filter by student:
studentkept = [1 2 3 5];
studentdata = csvread('somefile.txt');
studentdata = reshape(studentdata, size(studentdata, 1), 3, []); %pages no correspond to student
keptdata = studentdata(:, :, studentkept); %now, it's easy to filter
You can save it back to the original format by reshaping back to the flat format:
csvwrite('someotherfile.txt', reshape(keptdata, size(keptdata, 1), []));

카테고리

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

질문:

PF
2016년 1월 12일

답변:

2016년 1월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by