Error "Undefined function or variable"

I am receiving one of the following error messages. How can I resolve this issue?
Undefined function or variable 'segment_list'.
Code:
labels = {'cheduepalle';'fame';'chevuoi';'basta'};
segment_counter = 1;
for data_counter=1:num_of_samples
currVideo = data_files(data_counter).Video;
for label_counter = 1: length(currVideo.Labels)
if ismember(currVideo.Labels(label_counter).Name, labels)
s = struct('videoID', data_counter, 'start',currVideo.Labels(label_counter).Begin, 'end', currVideo.Labels(label_counter).End, 'label', currVideo.Labels(label_counter).Name);
segment_list(segment_counter) = s;
segment_counter = segment_counter + 1;
end
end
end

3 件のコメント

Cris LaPierre
Cris LaPierre 2021 年 9 月 18 日
I don't believe you have shared the line of code that is causing the error. Please copy the complete error essage (all the red text) and paste that here.
PaunBGD
PaunBGD 2021 年 9 月 18 日
Undefined function or variable 'segment_list'.
Error in main (line 287)
for idx = 1:length(segment_list)
Here is the code, starting from line 287:
for idx = 1:length(segment_list)
curr_face = [];
curr_lhand = [];
curr_rhand = [];
for Frameidx = segment_list(idx).start:segment_list(idx).end
curr_face = [curr_face; data_files(segment_list(idx).videoID).Video.Frames(Frameidx).Skeleton.PixelPosition(4,:)];
curr_lhand = [curr_lhand; data_files(segment_list(idx).videoID).Video.Frames(Frameidx).Skeleton.PixelPosition(8,:)];
curr_rhand = [curr_rhand; data_files(segment_list(idx).videoID).Video.Frames(Frameidx).Skeleton.PixelPosition(12,:)];
end
segment_list(idx).FaceArray = curr_face;
segment_list(idx).lHandArray = curr_lhand;
segment_list(idx).rHandArray = curr_rhand;
end
Cris LaPierre
Cris LaPierre 2021 年 9 月 18 日
It looks like segment_list never gets created. This could be because your for loops never end up running, or because your if conditional is never true. See Walter's reply below for more details.

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2021 年 9 月 18 日

0 投票

Perhaps num_of_samples is less than 1.
Perhaps data_files(data_counter).Video is empty for all num_of_samples different videos.
Perhaps none of the labels on any of the videos exactly match any of the values in the variable labels

2 件のコメント

Walter Roberson
Walter Roberson 2021 年 9 月 18 日
Right after you assign to the variable labels do
segment_list = struct('videoID', [], 'start', [], 'end', [], 'label', []);
This will initialize segment_list to an empty structure with the required fields.
Then if any of the "Perhaps" that I listed above hold true, then at least segment_list will be defined.
PaunBGD
PaunBGD 2021 年 9 月 20 日
Problem solved. Thank you so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeIntroduction to Installation and Licensing についてさらに検索

タグ

質問済み:

2021 年 9 月 18 日

コメント済み:

2021 年 9 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by