Uneven cell multiplication problem

조회 수: 1 (최근 30일)
John Spencer De Wit
John Spencer De Wit 2020년 5월 5일
댓글: Ameer Hamza 2020년 5월 6일
Hey guys.
I am struggling to multple two cells, i ask for an input an that only way i know how to save it is through using a cell. I then have to multiply 2 uneven cells with eac other with each other like multiplying a matrix.
function failure_analysis
prompt = {'Ox(Pa):','Oy(Pa):','Txy(Pa):','Angle(Degrees):','S(Pa):','X(Pa):','Xprime(Pa):','Y(Pa):','Yprime(Pa):'};
a = [inputdlg(prompt)]
sij1 = a(1);
sij2 = a(2);
sij3 = a(3);
angle = 45;
S = a(5);
X = a(6);
Xprime = a(7);
Y = a(8);
Yprime = a(9);
sij = [sij1;sij2;sij3];
F6 = 0;
O6 = 0;
T = [cosd(angle).^2 sind(angle).^2 2*cosd(angle).*sind(angle);
sind(angle).^2 cosd(angle).^2 -2*cosd(angle).*sind(angle);
-cosd(angle).*sind(angle) cosd(angle).*sind(angle) (cosd(angle).^2 -sind(angle).^2)]
O = sij*T
The problem happens in the last line of code.
Any help would be appreciated as i have to hand in the code next week monday.
Thanks

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 5월 5일
You first need to convert the output of inputdlg from char array to double. Try the following code
prompt = {'Ox(Pa):','Oy(Pa):','Txy(Pa):','Angle(Degrees):','S(Pa):','X(Pa):','Xprime(Pa):','Y(Pa):','Yprime(Pa):'};
a = inputdlg(prompt)
a = cellfun(@(x) str2double(x), a);
sij1 = a(1);
sij2 = a(2);
sij3 = a(3);
angle = 45;
S = a(5);
X = a(6);
Xprime = a(7);
Y = a(8);
Yprime = a(9);
sij = [sij1 sij2 sij3];
F6 = 0;
O6 = 0;
T = [cosd(angle).^2 sind(angle).^2 2*cosd(angle).*sind(angle);
sind(angle).^2 cosd(angle).^2 -2*cosd(angle).*sind(angle);
-cosd(angle).*sind(angle) cosd(angle).*sind(angle) (cosd(angle).^2 -sind(angle).^2)]
O = sij*T
  댓글 수: 2
John Spencer De Wit
John Spencer De Wit 2020년 5월 6일
Thanks it works perfectly
Ameer Hamza
Ameer Hamza 2020년 5월 6일
I am glad to be of help.

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

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by