Assign an incrementing variable to another variable name

조회 수: 3 (최근 30일)
Gulce Lale
Gulce Lale 2020년 11월 4일
댓글: Peter Perkins 2020년 11월 18일
This code can compile when the name_1 and other variables are given manually like I commented below: %name_1 = 'SID12_MVI0248_Trim.mp4'; etc.
However, what I am trying to do is this: I want the code to get this variables from excel sheet and assign the cell data to the variables. For example, it reads from the excel sheet 'face_info' and assume I have 10 videos in the excel sheet. I want every video's name should be updated as: name_1 = first name in the excel sheet and, name_2 = second name etc. and for each name(or video) I want it to compile the function B below which edits the videos in other scripts. So, I want to deal with each of the videos, but I always get the error Error using eval "Unrecognized function or variable 'name_1'." and "invalid use of 'name_' on the left side of an assignment".
I would really appreciate if someone could help me, thanks in advance!
video_name=[]; %name of the video
face_length =[]; %face length
nose_x = [];
nose_y = [];
non_blink_time = [];
[num1,txt1,data1] = xlsread('face_info.xlsx');
for j=1:length(txt1)
video_name = data1(:,1);
nose_x = data1(:,3);%x coordinate of the nose
nose_y = data1(:,4);%y coordinate of the nose
face_length = data1(:,5);%y length of the face
non_blink_time = data1(:,6); %non-blink start time
end
%disp(video_name{2});
videosPathToBeEdited = '/Users/user/Desktop/VideoCodes/';
editedVideosFolderPath = '/Users/user/Desktop/VideoCodes/';
videos = dir(videosPathToBeEdited);
cd(fullfile(editedVideosFolderPath));
faceCell = cell(video_number);
for i = 1:video_number
vidName = video_name{i+1}
disp(vidName);
vidPath = strcat(videosPathToBeEdited, vidName);
disp(vidPath);
V= VideoReader(vidPath);
RGB= readFrame(V);
imshow(RGB);
['name_' num2str(i)] = video_name{i+1};
non_blink_time = ['starting_second_' num2str(i)];
nose_x = ['nose_x_coord_' num2str(i)];
nose_y = ['nose_y_coord_' num2str(i)];
face_length = ['face_length_' num2str(i)];
disp(video_name{i+1});
%name_1 = 'SID12_MVI0248_Trim.mp4'; starting_second_1 = 1; nose_x_coord_1 = 954; nose_y_coord_1 = 520; face_length_1= 397; gender_1 = 'male';
B= conditionprep_behav(eval(['name_' num2str(i)]),sampling_rate_in_use,eval(['starting_second_' num2str(i)]),video_duration,eval(['nose_x_coord_' num2str(i)]),eval(['nose_y_coord_' num2str(i)]),eval(['face_length_' num2str(i)]),video_number,lum_mean,lum_std,resX,resY,elliptic_mask_threshold,video_duration_inname);
faceCell{i}.info = B;
faceCell{i}.sex = eval(['gender_' num2str(i)]);
end
save (['faceCell' video_duration_inname '.mat'],'faceCell');
  댓글 수: 3
Gulce Lale
Gulce Lale 2020년 11월 4일
Thank you very much, you really solved the problem!:)
Peter Perkins
Peter Perkins 2020년 11월 18일
Gulce, you will likely also be better off using readtable instead of xlsread.
Also, this loop seems suspect, because nothing in the body appears to change over the iterations:
for j=1:length(txt1)
video_name = data1(:,1);
nose_x = data1(:,3);%x coordinate of the nose
nose_y = data1(:,4);%y coordinate of the nose
face_length = data1(:,5);%y length of the face
non_blink_time = data1(:,6); %non-blink start time
end

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by