필터 지우기
필터 지우기

Undefined operator '*' for input arguments of type 'cell'. Error in eg9copy (line 23) RBV=((Vc*l​1+Vd*((l-l​2)/l)))

조회 수: 1 (최근 30일)
%%This program can be used to calculate the deameter of a shaft with two %%pulleys
%% Taking inputs for the variables of the pulleys and the shaft
clc a=42; %allowable shear stress
pi=3.14;
b=63; %allowable working stress
l= inputdlg('enter the span of the shaft l=');
d1= inputdlg('enter the diameter of the first pulley from the left d1(in m)=');
l1= inputdlg('enter the distance of the first pulley from the left l1(in m)=');
d1= inputdlg('enter the diameter of the second pulley from the left d2(in m)=');
l2= inputdlg('enter the distance of the second pulley from the right l2(in m)=');
Vc= inputdlg('enter the vertical load on first pulley Vc=');
Hc= inputdlg('enter the horizontal load on first pulley Hc=');
Vd= inputdlg('enter the vertical load on second pulley Vd=');
Hd= inputdlg('enter the horizontal load on second pulley Hd=');
%let RA and RB be the reactions at the bearing positions
%% For the vertical loading
RBV=((Vc*l1+Vd*(l-l2)/l))
fprintf('Vertical reaction at B=%4.2f N\n',RBV)
RAV=(Vc+Vd-RBV)
fprintf('Vertical reaction at A=%4.2f N\n',RAV)
%% For vertical bending moment
Mav=0; Mbv=0;
Mcv=RAV*l1;
fprintf('the vertical bending moment at C=%4.2f\n',Mcv)
Mdv=RBV*l2;
fprintf('the vertical bending moment at B=%4.2f\n',Mdv)
How can I solve this problem??
  댓글 수: 1
Stephen23
Stephen23 2017년 1월 8일
편집: Stephen23 2017년 1월 8일
Do not redefine pi like this:
pi=3.14;
The inbuilt value is much more precise
>> pi
ans =
3.14159265358979

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

채택된 답변

Stephen23
Stephen23 2017년 1월 8일
편집: Stephen23 2017년 1월 8일
"How can I solve this problem"
If you had read the inputdlg documentation then you would know that inputdlg returns a cell array containing the selected values: "The returned variable answer is a cell array containing one answer per text entry field"
Is a cell array containing strings the same a numeric array?
Can we do numeric operations on a cell array, or on a numeric array?
(hint: look for the word "numeric")
The warning message tells you that there is a cell array. Did you check this? This is something else the beginners need to learn: instead of writing code and having no idea what it is doing, they need to learn to understand what every line is doing, and they need to make sure that it does what they want, and that this means checking what they code is actually doing, not just what they think it is doing. Write every line and then test that line to make sure that it does exactly what you need it to do.
MATLAB has lots of ways to help you do this, for example the great documentation, and a very convenient workspace viewer. Simply looking at the workspace would have told you that these variables are cell arrays and not numeric arrays.
To fix your code convert the string values to a numeric using str2double:
>> C = inputdlg('enter the span of the shaft l=')
C =
'5'
>> class(C)
ans =
cell
>> N = str2double(C{1})
N =
5
>> class(N)
ans =
double
Also note that it is a very bad idea to redefine pi, especially with such an imprecise value like 3.14. The inbuilt value of pi is much higher precision:
>> pi
ans =
3.14159265358979
Also note that you can get rid of the multiple dialog boxes with just one:
pmt = {'enter the span of the shaft l=',...
'enter the diameter of the first pulley from the left d1(in m)=',...
'enter the distance of the first pulley from the left l1(in m)=',...
'enter the diameter of the second pulley from the left d2(in m)=',...
'enter the distance of the second pulley from the right l2(in m)=',...
'enter the vertical load on first pulley Vc=',...
'enter the horizontal load on first pulley Hc=',...
'enter the vertical load on second pulley Vd=',...
'enter the horizontal load on second pulley Hd='};
out = inputdlg(pmt);
vec = str2double(out);
%
l = vec(1);
d1 = vec(2);
l1 = vec(2);
etc
  댓글 수: 10
Rohan Maharjajn
Rohan Maharjajn 2017년 1월 26일
@Stephen Cobeldick Thank you very much for your help and guidance. I was able to publish the result from the command prompt. But, is there any way I can publish it from the editor? while doing so , I was again stuck in an in finite loop. I have made all the corrections you told me .
Stephen23
Stephen23 2017년 1월 29일
편집: Stephen23 2017년 1월 29일
"is there any way I can publish it from the editor?"
Of course you can do this: publish can be called in any script or function. Just remember that if you call publish inside the same function that you are publishing then you will always get into an infinite loop. So call it from another script or function.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by