MATLAB Answers

Unable to perform assignment because the left and right sides have a different number of elements.

13 ビュー (過去 30 日間)
Daniel Franca
Daniel Franca 2019 年 11 月 24 日
Commented: Star Strider 2019 年 11 月 25 日
Hello everyone, I really need some help overhere.
So, I have a dataset 'c' , which is a 641x1 cell.
My goal is to solve a cubic equation, using the cell values of 'c' , to find de variable 'a', for each value of 'c'.
I have been trying to do that, but matlab gives me the following error message :
"Unable to perform assignment because the left and right sides have a different number
of elements."
Can anyone help me ? Thanks a lot!
clc
%Co = DEF/P da curva linear inicial
Co=0.000252; %Compliance Inicial
a0=30; %Comprimento inicial da trinca
delta=10; %valor delta de correção
B=25; %Base do Substrato
h=9.5; % Altura do substrato
E1=200000; %Modulo de Elasticidade Longitudinal
v=0.30; %poisson
G13=E1/(2*(1+v)); %modulo de elasticidade transversal%
%Calculando Ef%
Ef=((Co-((12*(a0+ delta))/(5*B*h*G13)))^(-1))*((8*(a0+delta)^3)/(B*h^3));
syms a
for i=1:length(c)
eq= c(i)==(8*a^3)/(Ef*B*h^3)+(12*a)/(5*B*h*G13);
aeq(i)= solve(eq,a);
end

  0 件のコメント

サインイン to comment.

採用された回答

Star Strider
Star Strider 2019 年 11 月 24 日
Since we do not know more about what you are calculating, the easiest way to deal with this problem is to create a cell array for ‘aeq’:
for i=1:length(c)
eq= c(i)==(8*a^3)/(Ef*B*h^3)+(12*a)/(5*B*h*G13);
aeq{i}= solve(eq,a);
end
Note the curly braces {} denoting cell array indexing.
See the documentation on Cell Arrays if you are not familiar with them, to understand how to work with them.

More Answers (1)

Walter Roberson
Walter Roberson 2019 年 11 月 24 日
You are constructing a cubic. solve() on a cubic will return 3 answers. You are trying to store the three answers into the single location aeq(i)
Is it possible that you only want real-valued answers, or that you only want positive answers, or that you want the one answer with the highest absolute value?

  1 件のコメント

Daniel Franca
Daniel Franca 2019 年 11 月 25 日
Yup!You're absolutely right about the 3 answers. Solved it! Thanks!

サインイン to comment.

サインイン してこの質問に回答します。


Translated by