separation matrix in several matrices, "i" times
3 views (last 30 days)
Show older comments
So, I want to calculate the matrix (JAC). All the results throw me in a single matrix, instead of for each point (x,y,z) of the new matrix.
So how would you do that for each of (x,y,z) a new matrix
Code: a1 = 250; d1 = 645; a2 = 1000; a3 = 230; d2 = 1587.4;
% inputing for GUI minimal
x_min = 2;
y_min = 3;
z_min = 4;
% inputing for GUI resolution
x_res = 1;
y_res = 1;
z_res = 1;
% inputing for GUI maximal
x_max = 4;
y_max = 5;
z_max = 6;
% vector
x = [x_min:x_res:x_max]';
y = [y_min:y_res:y_max]';
z = [z_min:z_res:z_max]';
% calculation of internal coordinates
S3 = sin(a3);
C3 = cos(a3);
B = d2*S3 - a3*C3;
SB = sqrt(-(B*B)+a3*a3+d2*d2);
q3 = atan2(a3,d2)-atan2(B, SB);
S2 = sin(a2);
C2 = cos(a2);
q2 = atan2(S2,C2);
if length(x)==length(y)
dv =length(x);
for i=1:dv
q1(i) = atan2(y(i),x(i));
end
else
display('vektorja x in y nista enako dolga !!');
end
% calculate Jac matrix
A(i) = (-d2*cos(q1(i))*cos(q2)*sin(q3)-d2*cos(q1(i))*sin(q2)*cos(q3)-a3*cos(q1(i))*cos(q2)*cos(q3)+a3*cos(q1(i))*sin(q2)*sin(q3)-a2*cos(q1(i))*cos(q2)+a1*sin(q1(i))); % "levi zgoraj"
B(i) = (d2*sin(q1(i))*sin(q2)*sin(q3)-d2*sin(q1(i))*cos(q2)*cos(q3)+a3*sin(q1(i))*sin(q2)*cos(q3)+a3*sin(q1(i))*cos(q2)*sin(q3)+a2*sin(q1(i))*sin(q2)+a1*cos(q1(i))); % "sredina zgoraj"
C(i) = (-d2*sin(q1(i))*cos(q2)*cos(q3)+d2*sin(q1(i))*sin(q2)*sin(q3)+a3*sin(q1(i))*cos(q2)*sin(q3)+a3*sin(q1(i))*sin(q2)*cos(q3)-a2*sin(q1(i))*cos(q2)+a1*cos(q1(i))); % "desno zgoraj"
D(i) = (-d2*sin(q1(i))*cos(q2)*sin(q3)-d2*sin(q1(i))*sin(q2)*cos(q3)-a3*sin(q1(i))*cos(q2)*cos(q3)+a3*sin(q1(i))*sin(q2)*sin(q3)-a3*sin(q1(i))*cos(q2)+a3*cos(q1(i))); % "levi v sredini"
E(i) = (-d2*cos(q1(i))*sin(q2)*sin(q3)+d2*cos(q1(i))*cos(q2)*cos(q3)-a3*cos(q1(i))*sin(q2)*cos(q3)-a3*cos(q1(i))*cos(q2)*sin(q3)-a3*cos(q1(i))*sin(q2)+a3*sin(q1(i))); % "sredina v sredini"
F(i) = (d2*cos(q1(i))*cos(q2)*cos(q3)-d2*cos(q1(i))*sin(q2)*sin(q3)-a3*cos(q1(i))*cos(q2)*sin(q3)-a3*cos(q1(i))*sin(q2)*cos(q3)+a3*cos(q1(i))*cos(q2)+a3*sin(q1(i))); % "desni v sredini"
G(i) = (d2*sin(q2)*sin(q3)+d2*cos(q2)*cos(q3)+a3*sin(q2)*cos(q3)+a3*cos(q2)*sin(q3)+a2*sin(q2)+d1); % "levi spodaj"
H(i) = (d2*cos(q2)*sin(q3)+d2*sin(q2)*cos(q3)+a3*cos(q2)*cos(q3)-a3*sin(q2)*sin(q3)+a2*cos(q2)+d1); % "sredinski spodaj"
I(i) = (d2*sin(q2)*cos(q3)+d2*cos(q2)*sin(q3)-a3*sin(q2)*sin(q3)+a3*cos(q2)*cos(q3)+a2*sin(q2)+d1); % "desni spodaj"
Jac = [A, B, C; D, E, F; G, H, I]
10 Comments
Image Analyst
on 27 Sep 2012
That's happened to me to. What happens more often is when I get done typing and move my right hand over to the mouse and accidentally bump the "back" button on the side of the mouse with my thumb. Sometimes going forward won't recover the text you had typed in. For that reason, and for a reason like you described, you need to use Lazarus. http://getlazarus.com/ I can't tell you how many times it's saved me a ton of re-typing. Basically it remembers what you typed into the last several edit boxes so on any web page, you can resurrect any of those texts that you've typed by right-clicking and selecting the text you want to paste into the edit box.
Star Strider
on 27 Sep 2012
Thank you for the Lazarus reference. I'll look into it.
You comment also seems relevant to the current thread ‘What’s missing from MATLAB Central...’. I suggest you post a version of it there as well.
Answers (5)
Star Strider
on 26 Sep 2012
Edited: Star Strider
on 26 Sep 2012
First, I suggest not using i or j as variables. MATLAB uses them for its imaginary operators, and using them as variables in your code could be confusing if you also have complex numbers. (I use k1 for outer loops, k2 for the next level of inner loops, and so on. It works for me.)
Second, I am not certain what you are doing, but with that caution, I suggest you consider something like this:
for i = 1:something
A(i) = ...
.
.
.
I(i) = ...
end
Then, to create your Jac matrix:
Jac(1,1,:) = A;
Jac(1,2,:) = B;
.
.
.
Jac(3,3,:) = I;
That is probably the easiest (although not the neatest) way for you to create your Jac matrix. At least you do not have to re-write large parts of your code to create it that way.
I am guessing how you want to set up your Jac matrix. Change the code as necessary to do what you intend.
mirch
on 27 Sep 2012
Edited: mirch
on 27 Sep 2012
1 Comment
Star Strider
on 27 Sep 2012
1. You do not need the k3 loop. It does the same thing three times and the results do not change.
2. What do you want to do in your k4 loop? You are not doing anything with your Jac matrix here.
3. What do you want to do in you k5 loop? What parts of Jac do you want the determinant of? Your Jac matrix is [3 x 3 x 4]. Your reference to Jac(k5) is calling the single elements [Jac(1,1,1) Jac(2,1,1) Jac(3,1,1) Jac(1,2,1)] in order.
4. I do not know what you are doing in your k6 loop, but we will consider that after we get your k4 and k5 loops doing what you want them to do.
mirch
on 27 Sep 2012
5 Comments
Star Strider
on 2 Oct 2012
Edited: Star Strider
on 2 Oct 2012
You cannot transpose a matrix with more than two dimensions, so you cannot simply transpose w since your w matrix is [3 x 3 x 4]. I do not know what in that situation you want to transpose, so I cannot give you specific advice. However, if you want to transpose every page of the 3rd dimension of w, I suggest:
for k6 = 1:dv
wt(:,:,k6) = w(:,:,k6)';
end
If you want to do something else, change that code appropriately.
Also, you have two options for transposing your w matrix, since it is complex.
The usual transpose operator (') is actually the complex conjugate transpose. So if you want the complex conjugate transpose, and we define wt as the transpose of w, do as I described in the previous loop.
If you want to do the transpose and not also do the complex conjugate operation, use the ‘dot-transpose’ operator (.') and do this:
for k6 = 1:dv
wt(:,:,k6) = w(:,:,k6).';
end
What you do depends on what you want to do with your wt matrix later.
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!