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

1 回表示 (過去 30 日間)
Sunusi Abdullahi
Sunusi Abdullahi 2023 年 4 月 28 日
編集済み: Walter Roberson 2023 年 4 月 28 日
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 Center および File ExchangeWhos についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by