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

2 次查看(过去 30 天)
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

回答(1 个)

CAM
CAM 2023-4-28
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.

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by