Here's a sample of the excel.
How do I isolate rows from a table, containing the same column value?
조회 수: 5 (최근 30일)
이전 댓글 표시
I received a very large spreadsheet document with data of students, per student the columns exist of name, school, date of birth etc. I imported this spreadsheat as a table in matlab, and set all columns as strings.
The goal is to extract rows of students who went to the same highschool. Let's say this value is in collumn 3 and is alphabetically ordered.
I tried this in matlab by iterating and trying to save the students in a new table when the schools match. I found a solution where I have to copy one school in my code and then it gives a clean table with all students who went to that school.
But since there are 3000 different schools in the document it would be nice let a loop iterate over all schools and do all the work in one time.
This is what I thought would have worked but it didnt't:
MASSADOC = sortrows(MASSADOC,'school','ascend');
T=table;
Names=strings;
for i =1:15310%there are 15310 rows in my document
Names(i)=MASSADOC.Omschrijvingin(i); %to get a string array with all schools
end
U=unique(Names); %a string array with all schools 1 time in it
for i = 1:size(U)
x=U(i);
for j = 1:15310
if MASSADOC.school(j)==U(i)
T(j,:)=MASSADOC(j,:);
else
end
writetable(T, x+'.xlsx','Sheet',1);
end
end
댓글 수: 3
채택된 답변
Guillaume
2019년 12월 5일
편집: Guillaume
2019년 12월 5일
There is no need to sort the table beforehand:
[group, schoolname] = findgroups(MASSADOC.school); %get unique schools and assign unique group to each one
for g = 1:numel(schoolname) %iterate over each school/group
writetable(MASSADOC(group == g, :), sprintf('%s.xlsx', schoolname{g})); %and save the rows that match the group
end
댓글 수: 6
Guillaume
2019년 12월 6일
Ultimately, it all depends on your computer but most likely, Excel will struggle on a big excel sheet before matlab does since excel needs to keep in memory not only the cell values, but their formatting, formulae and other properties which matlab doesn't store.
In addition, in matlab you can always resort to datastore and tall arrays to deal with data that would never fit in memory.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!