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
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!