필터 지우기
필터 지우기

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

조회 수: 100 (최근 30일)
Hi everyone, I am trying to run this code:
clear all
close all
clc
syms x(t) y(t) z(t) A B C D E FF G H I J K LL MM N O P Q R S
eqn1 = diff(x(t),t) == 1/ A * ((B * C - B * x(t))) - (x(t) * D * E - FF*((y(t) * z(t)^2)/(z(t)^2 + G * z(t) + G * H))) / ((1/I) + 1/(J * (((K*(FF* x(t) * D * E - ((y(t) * z(t)^2)/(z(t)^2 + G * z(t) + G*H))))) + LL * (((G * FF * x(t) * D * E/z(t)) - ((y(t) * G * z(t))/(z(t)^2 + G * z(t) + G*H)))) + MM * ((((G * H *FF* x(t) * D * E/z(t)^2) - ((y(t) * G * H)/(z(t)^2 + G * z(t) + G*H))))))) / (K * (FF * x(t) * D * E - ((y(t) * z(t)^2)/(z(t)^2 + G * z(t) + G*H)))));
eqn2 = diff(y(t),t) == (x(t) * D * E - FF*((y(t) * z(t)^2)/(z(t)^2 + G * z(t) + G*H))) / ((1/I) + 1/(J * (((K*(FF* x(t) * D * E - ((y(t) * z(t)^2)/(z(t)^2 + G * z(t) + G * H)) ) + LL * (((G * FF * x(t) * D * E/z(t)) - (( y(t) * G * z(t))/(z(t)^2 + G * z(t) + G*H)))) + MM * ((((G * H * FF * x(t) * D * E / z(t)^2) - ((y(t) * G * H)/(z(t)^2 + G * z(t) + G * H))))))/ (K * (FF * x(t) * D * E - (( y(t) * z(t)^2)/(z(t)^2 + G * z(t) + G * H))))))) - 0.162 * exp(-5153/E) * (((N * (( y(t) * G * H)/(z(t)^2 + G * z(t) + G*H)))/O) - 1)^2 * (P / ((N * (((y(t) * G * H)/(z(t)^2 + G * z(t) + G * H))))) / O));
eqn3 = z(t) + 2 * N - ((y(t) * G * z(t))/(z(t)^2 + G * z(t) + G*H)) - 2 * (( y(t) * G * H)/(z(t)^2 + G * z(t) + G*H)) - ((N * Q * z(t))/(z(t)^2 + Q * z(t) + Q*R)) - 2 * ((N * Q * R)/(z(t)^2 + Q * z(t) + Q*R)) - S/z(t) == 0;
eqns = [eqn1 eqn2 eqn3];
vars = [x(t); y(t); z(t)];
origVars = length(vars);
M = incidenceMatrix(eqns, vars);
[eqns, vars] = reduceDifferentialOrder(eqns, vars);
isLowIndexDAE(eqns,vars);
f = daeFunction(eqns,vars, A, B, C, D, E, FF, G, H, I, J, K, LL, MM, N, O, P, Q, R, S);
A = 1.5e-6;
B = 1.66667e-5;
C = 6.51332e-2;
D = 8.314;
E = 323.15;
FF = 149;
G = 6.24;
H = 5.68e-5;
I = 4.14e-6;
J = 7.25E-2;
K = 2.98e-9;
LL = 2.35e-9;
MM = 1.69e-9;
N = 8;
O = 1.07e-7;
P = 10;
Q = 1.7e-3 ;
R = 6.55e-8;
S = 5.3e-8 ;
F = @(t, Y, YP) f(t, Y, YP, A, B, C, D, E, FF, G, H, I, J, K, LL, MM, N,O, P, Q, R, S);
vars;
y0est = [4.58E-02; 1.58; 1];
yp0est = zeros(3,1);
opt = odeset('RelTol', 10.0^(-7), 'AbsTol' , 10.0^(-7));
[y0, yp0] = decic(F, 0, y0est, [], yp0est, [], opt);
[tSol,ySol] = ode15i(F, [6720, 27840], y0, yp0, opt);
for k = 1:origVars
S{k} = char(vars(k));
end
However, I get the error message:
Unable to perform assignment because brace indexing is not supported for variables of this type.
Error in Example01Sept2018 (line 57)
S{k} = char(vars(k));
The Debugging points me to:
for k = 1:origVars
S{k} = char(vars(k));
end
When I change to:
for k = 1:origVars
S(k) = char(vars(k));
end
I get an error message:
Unable to perform assignment because the left and right sides have a different number of elements.
Error in Example01Sept2018 (line 57)
S(k) = char(vars(k));
What can I do?
  댓글 수: 2
NN
NN 2020년 12월 12일
i also got the same error ,
Unable to perform assignment because brace indexing is not supported for variables of this type.
do not know how to solve this.Please help
y=xlsread('DelhiTRAIN2.xlsx');
XTrain=y((1:end),1:5);
YTrain=y((1:end),6);
m = min([XTrain(:)],[],2);
M = max([XTrain(:)],[],2);
idxConstant = M == m;
for i = 1:numel(XTrain)
XTrain{i}(idxConstant,:) = [];
end
Walter Roberson
Walter Roberson 2020년 12월 12일
m = min([XTrain(:)],[],2);
The (:) forces a column vector. Why are you asking for the min() along the second dimension for something that is a column vector? The result is just going to be the same as XTrain(:)
XTrain{i}(idxConstant,:) = [];
The first output of xlsread() is never a cell array, so y() indexed will not be a cell array, so XTrain will not be a cell array, so you should not be assigning into XTrain{i}
What is your purpose in that loop?

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

채택된 답변

Walter Roberson
Walter Roberson 2018년 9월 1일
You have
S = 5.3e-8 ;
but later you want to use S to store the names of the variables. I do not recommend re-using the name of a numeric coefficient for something completely different: it gets too confusing.
But if it is for some reason very important to use the name S in both cases, then you will need to assign something to change S into a cell array, such as
S = cell(origVars, 1);
Or you can skip the initialization and the explicit loop and use
S = arrayfun(@char, vars, 'uniform', 0);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by