How to populate table in for loop
조회 수: 13 (최근 30일)
이전 댓글 표시
I am trying to populate a preallocated table in a foor loop, where each iteration populates a new row. My code is as follows:
files = what('March\MatFile'); %list all the mat-files in the folder
num = length(files.mat);
folder = dir('March\MatFile'); var = zeros([num,1]); GenRegTable = table(var, var, var); GenRegTable.Properties.VariableNames = {'n','GenID','GenRegCount'}; tic for i = 1:num Gen = files.mat{i}; %generator mat file split = strsplit(Gen,'.'); GenID = split{1};
S = load(['March\MatFile\' Gen]); %structure
T = S.T; %table
row = height(T);
newtable = T;
count1 = height(newtable);
toDelete = newtable.GenReg == 0;
newtable(toDelete,:) = [];
count2 = height(newtable);
name = [GenID '.mat'];
save(name,'newtable');
GenRegTable.n(i) = i;
GenRegTable.GenID(i) = GenID; % this line returns error
GenRegTable.GenRegCount(i) = count2;
toc
end
I want to specify which specific column and row to fill where row is determined by i. I can populate the first column and row but I am getting an error when I try to populate the second column. The error I get is:
"Unable to perform assignment because the left and right sides have a different number of elements."
GenID is a text is '2018_001_03' count 2 is just going to be a number and I don't get an error when I try to populate this column. How do I populate a column with text??
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!