Borrar filtros
Borrar filtros

I am having empty cells while saving the extracted features inside loops

1 visualización (últimos 30 días)
Hi,
Can someone help me with my code below. I am extracting features inside a loop from .csv files however, while I saved the features, I found that only one cell has the extracted values while the remaining cells were empty. I dont know where I miss it, please.
%% Function to read .csv frames
function Feature_Engineering
fb = fopen('NameListP500.txt','r');
FileNameP = fgetl(fb);
RoundP = str2num(FileNameP);
Extracted = {};
for Ct = 1:RoundP
FileNameP = fgetl(fb);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fr = fopen('NameList500.txt','r');
FileName = fgetl(fr);
Round = str2num(FileName);
for Ct = 1:Round
try
FileName = fgetl(fr);
[Extracted] = Feature_Engineering(FileName,FileNameP,Ct,Extracted);
catch ME
disp('mistake to read frame number'); disp(Ct);
end
%imtool close all
%close all
end
end

Respuestas (1)

CAM
CAM el 28 de Abr. de 2023
You never tell Matlab to put the next value of Extracted into a new cell. I.e., you have not increased the cell array index with each iteration of Ct. I suggest preallocating Extracted before the Round for-loop, then write a new value to Extracted(Ct) in each iteration.
By the way you also use the variable Ct to loop both Round and RoundP; I am surprised Matlab has not given you an error.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by