How to populate table in for loop

8 visualizaciones (últimos 30 días)
Karina
Karina el 24 de Abr. de 2018
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??

Respuestas (0)

Categorías

Más información sobre Tables en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by