I am having empty cells while saving the extracted features inside loops
2 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
CAM
on 28 Apr 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.
0 Comments
See Also
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!