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

6 visualizaciones (últimos 30 días)
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');

Respuesta aceptada

Walter Roberson
Walter Roberson el 28 de Mzo. de 2020
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 comentarios
Kong
Kong el 29 de Mzo. de 2020
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
Walter Roberson
Walter Roberson el 29 de Mzo. de 2020
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Types en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by