필터 지우기
필터 지우기

1x4 matrix assigning values to a variable

조회 수: 1 (최근 30일)
Joshua
Joshua 2014년 3월 3일
댓글: Azzi Abdelmalek 2014년 3월 3일
So say i have a 1x4 matrix like this :
b =
7.1555540396380393239417370831804
1.993753283660616260599428304438
0.12926899451597696747749296398951
-11.278576317814632552018658351608
And i want to set any values greater than 1 to b1, then b2, then b3 etc. The original values of the matrix can change completely so i need it to be robust in that it will just either assign the variable or move on to the next value. I hope that makes sense. For this example I'd want to receive back b1=7.155.... b2=1.9937....
so far i though of this but it doesnt work when the x matrix changes size
x=b(find(b>1))
b1=x(1)
b2=x(2)
b3=x(3)
b4=x(4)
Thanks,
Joshua
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2014년 3월 3일
This is not clear. How b, b1, b2, ... are related?
Joshua
Joshua 2014년 3월 3일
b is just a matrix, i just want to label to values of the matrix that are above one as b1, b2 etc

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

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 3월 3일
편집: Azzi Abdelmalek 2014년 3월 3일
x=b(find(b>1))
x contains all what you want. Why do you want to creates the variables a1, a2, ...?
Read this link
  댓글 수: 2
Joshua
Joshua 2014년 3월 3일
This is my full script:
clear
g=9.81;
h=10;
u=1.5;
syms a b c d
a=u./sqrt(g.*h)
h=10;
d=0.5;
c=0.5;
b=solve(((a^(2).*b^4)/2)+2.*c.*a^(2).*b^(3)-(2-2.*d+a^(2)).*b^(2)-(4.*c+2.*c.*a^(2)-4).*b+((a^(2)/2)+4.*c-2.*c^(2).*d-2),b,'MaxDegree',3);
x=b(find(b>1))
b1=x(1)
b2=x(2)
b3=x(3)
b4=x(4)
i want to use the values given in the solve function that are greater than 1 in another equation next, but the variables in the solve function can change so the b matrix might have all values above 1 or none, if that makes sense?
Azzi Abdelmalek
Azzi Abdelmalek 2014년 3월 3일
Ok, until
x=b(b>1)
it's ok
why
b1=x(1) ?
x contains all what you want, why to create other variables b1, b2,...?

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

카테고리

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