Unable to perform assignment because brace indexing is not supported for variables of this type.

I am doing this code each frame of videos.
Plese let me know how to fix this error.
clear all
close all
%// read the video:
list = dir('*.avi')
% loop through the filenames in the list
for k = 1:length(list)
reader = VideoReader(list(k).name);
vid = {};
while hasFrame(reader)
vid{end+1} = readFrame(reader);
end
for i=1:25
fIdx(i) = i; %// do it for frame 1 ~ 25
frameGray{i} = rgb2gray(vid{fIdx(i)});
data{i} = frameGray{i}';
data{i} = double(data{i});
opt.init_num_secants = 180;
idx1{i} = random('unid',size(data{i}, 2), opt.init_num_secants, 1);
idx2{i} = random('unid',size(data{i}, 2), opt.init_num_secants, 1);
secants{i} = data{i}(:, idx1{i})-data{i}(:, idx2{i});
D1{i} = abs(secants{i});
numSecants = size(data{i},1);
options.landmarks = 1:180;
[geo{i}] = IsomapII(D1{i}, 'k', 3, options);
secants{i} = geo{i}/norm(geo{i},2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%Parameter setting
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
opt.outer_iterations = 1000;
switch 'l-bfgs'
case 'grad'
opt.linear_solver = 'grad';
opt.tau = 1e-1; % gradient step size
opt.inner_iterations = 10;
opt.beta1 = 1e-1; opt.beta2 = 1e-1; %penalty parameters
opt.eta1 = 1; opt.eta2 = 1; %lagrangian update
case 'cgs'
opt.linear_solver = 'cgs';
opt.linear_iterations = 10;
opt.inner_iterations = 1;
opt.beta1 = 1; opt.beta2 = 1; %penalty parameters
opt.eta1 = 1.618; opt.eta2 = 1.618; %lagrangian update
case 'l-bfgs'
opt.linear_solver = 'l-bfgs';
opt.linear_iterations = 3;
opt.lbfgs_rank = 5;
opt.inner_iterations = 1;
opt.beta1 = 1; opt.beta2 = 1; %penalty parameters
opt.eta1 = 1.618; opt.eta2 = 1.618; %lagrangian update
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%End parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
delta = 0.3; %max-margin parameter
funA = @(z) funA_secants_WY(z, secants{i});
funAT = @(z) funAT_secants_WY(z, secants{i});
b = ones(numSecants, 1);
ticID = tic;
[P{i}, L{i}, q{i}, Lambda{i}, w{i}] = NuMax(funA, funAT, b, delta, opt);
toc(ticID);
[U{i}, S{i}, V{i}] = svd(P{i});
r{i} = rank(P{i});
U1{i} = U{i}(:, 1:r{i});
U1{i} = (U1{i} - min(U1{i}(:)))/(max(U1{i}(:))-min(U1{i}(:)));
Phi_NuMax = (U{i}(:, 1:r{i})*(S{i}(1:r{i}, 1:r{i}).^(1/2)))';
data = data{i};
Y = Phi_NuMax * data;
end
end
X = cell2mat(Y');

 채택된 답변

At the bottom of your loop you have
data = data{i};
That replaces the cell array data that contains the cell with framegray{1}', with the contents of that entry, so instead of data being a cell array with framegray{1}' inside it, data would become the contents directly, framegray{1}' not inside a cell array. Then in the second iteration of the loop when you go to assign to data{2} then data is not a cell array and you are not permitted to do that.
You should be asking yourself why you are doing the
data = data{i};

댓글 수: 5

Thank you so much.
I want to multiply the cell, but I don't know how to deal with this problem.
When I delete "data = data{i};", I got error like this.
clear all
close all
clear all
close all
%// read the video:
list = dir('*.avi')
% loop through the filenames in the list
for k = 1:length(list)
reader = VideoReader(list(k).name);
vid = {};
while hasFrame(reader)
vid{end+1} = readFrame(reader);
end
for i=1:25
fIdx(i) = i; %// do it for frame 1 ~ 60
frameGray{i} = rgb2gray(vid{fIdx(i)});
data{i} = frameGray{i}';
data{i} = double(data{i});
opt.init_num_secants = 180;
idx1{i} = random('unid',size(data{i}, 2), opt.init_num_secants, 1);
idx2{i} = random('unid',size(data{i}, 2), opt.init_num_secants, 1);
secants{i} = data{i}(:, idx1{i})-data{i}(:, idx2{i});
D1{i} = abs(secants{i});
numSecants = size(data{i},1);
options.landmarks = 1:180;
[geo{i}] = IsomapII(D1{i}, 'k', 3, options);
secants{i} = geo{i}/norm(geo{i},2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%Parameter setting
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
opt.outer_iterations = 1000;
switch 'l-bfgs'
case 'grad'
opt.linear_solver = 'grad';
opt.tau = 1e-1; % gradient step size
opt.inner_iterations = 10;
opt.beta1 = 1e-1; opt.beta2 = 1e-1; %penalty parameters
opt.eta1 = 1; opt.eta2 = 1; %lagrangian update
case 'cgs'
opt.linear_solver = 'cgs';
opt.linear_iterations = 10;
opt.inner_iterations = 1;
opt.beta1 = 1; opt.beta2 = 1; %penalty parameters
opt.eta1 = 1.618; opt.eta2 = 1.618; %lagrangian update
case 'l-bfgs'
opt.linear_solver = 'l-bfgs';
opt.linear_iterations = 3;
opt.lbfgs_rank = 5;
opt.inner_iterations = 1;
opt.beta1 = 1; opt.beta2 = 1; %penalty parameters
opt.eta1 = 1.618; opt.eta2 = 1.618; %lagrangian update
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%End parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
delta = 0.3; %max-margin parameter
funA = @(z) funA_secants_WY(z, secants{i});
funAT = @(z) funAT_secants_WY(z, secants{i});
b = ones(numSecants, 1);
ticID = tic;
[P{i}, L{i}, q{i}, Lambda{i}, w{i}] = NuMax(funA, funAT, b, delta, opt);
toc(ticID);
[U{i}, S{i}, V{i}] = svd(P{i});
r{i} = rank(P{i});
U1{i} = U{i}(:, 1:r{i});
U1{i} = (U1{i} - min(U1{i}(:)))/(max(U1{i}(:))-min(U1{i}(:)));
Phi_NuMax{i} = (U{i}(:, 1:r{i})*(S{i}(1:r{i}, 1:r{i}).^(1/2)))';
Y = Phi_NuMax{i} * data{i}';
end
end
X = cell2mat(Y');
Your original code had
data = data{i};
Y = Phi_NuMax * data;
which for the calculation of Y was equivalent to
Y = phi_NuMax * data{i};
That code worked for the first iteration.
Your revised code has
Y = Phi_NuMax{i} * data{i}';
with data{i} being transposed relative to what worked for one iteration before.
Thank you so much!
I used this code.
Y = Phi_NuMax{i} * data{i};
I have same problem another example.
There are lots of videos in folder.
Could you check this error too?
clear all
close all
%// read the video:
list = dir('*.avi')
% loop through the filenames in the list
for k = 1:length(list)
reader = VideoReader(list(k).name);
vid = {};
while hasFrame(reader)
vid{end+1} = readFrame(reader);
end
for i=1:25
fIdx(i) = i; %// do it for frame 1 ~ 60
frameGray{i} = rgb2gray(vid{fIdx(i)});
data{i} = frameGray{i};
data{i} = double(data{i});
n = size(frameGray{i}, 1);
opt.init_num_secants = n;
idx1{i} = random('unid',size(data{i}, 2), opt.init_num_secants, 1);
idx2{i} = random('unid',size(data{i}, 2), opt.init_num_secants, 1);
secants{i} = data{i}(:, idx1{i})-data{i}(:, idx2{i});
D1{i} = abs(secants{i});
numSecants = size(data{i},1);
options.landmarks = 1:n;
[geo{i}] = IsomapII(D1{i}, 'k', 3, options);
secants{i} = geo{i}/norm(geo{i},2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%Parameter setting
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
opt.outer_iterations = 1000;
switch 'l-bfgs'
case 'grad'
opt.linear_solver = 'grad';
opt.tau = 1e-1; % gradient step size
opt.inner_iterations = 10;
opt.beta1 = 1e-1; opt.beta2 = 1e-1; %penalty parameters
opt.eta1 = 1; opt.eta2 = 1; %lagrangian update
case 'cgs'
opt.linear_solver = 'cgs';
opt.linear_iterations = 10;
opt.inner_iterations = 1;
opt.beta1 = 1; opt.beta2 = 1; %penalty parameters
opt.eta1 = 1.618; opt.eta2 = 1.618; %lagrangian update
case 'l-bfgs'
opt.linear_solver = 'l-bfgs';
opt.linear_iterations = 3;
opt.lbfgs_rank = 5;
opt.inner_iterations = 1;
opt.beta1 = 1; opt.beta2 = 1; %penalty parameters
opt.eta1 = 1.618; opt.eta2 = 1.618; %lagrangian update
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%End parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
delta = 0.3; %max-margin parameter
funA = @(z) funA_secants_WY(z, secants{i});
funAT = @(z) funAT_secants_WY(z, secants{i});
b = ones(numSecants, 1);
ticID = tic;
[P{i}, L{i}, q{i}, Lambda{i}, w{i}] = NuMax(funA, funAT, b, delta, opt);
toc(ticID);
[U{i}, S{i}, V{i}] = svd(P{i});
r{i} = rank(P{i});
U1{i} = U{i}(:, 1:r{i});
U1{i} = (U1{i} - min(U1{i}(:)))/(max(U1{i}(:))-min(U1{i}(:)));
Phi_NuMax{i} = (U{i}(:, 1:r{i})*(S{i}(1:r{i}, 1:r{i}).^(1/2)))';
Y{i} = Phi_NuMax{i} * data{i};
Y{i} = reshape(Y{i},[],1);
end
Y = cell2mat(Y);
% make csv file whose name matches the avi file
[~,name] = fileparts(list(k).name); % get the file name without the extension
outfile = strcat(name,'.csv')
csvwrite(outfile,Y); % assumes you have already assigned the array X earlier
end
Y = cell2mat(Y);
is within your for k loop. You build up cell Y the first time, doing all for i iterations, and then you replace Y with a matrix instead of a cell, and then you go for the second iteration of k, but Y is still the matrix, not a cell array.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2020년 3월 28일

댓글:

2020년 3월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by