- Please include your code as plain ascii, not as a graphics.
- Some variables in the code you posted are undefined. So even if we took the time to write down your code again, we cannot test it.
- What do you mean by But when I try to make a matrix 2x2 with those variables as it's components, it doesn't work. What is the error message you get ?
Define matrix array as functions
1 view (last 30 days)
Show older comments
I am a student, and looking for any kind help to correct my work bellow :
I define some variables as function of cos (t), and when I run this program, it works, no error information at the command window, and also they do have the same length.
But when I try to make a matrix 2x2 with those variables as it's components, it doesn't work. I would be grateful if somebody will kindly help me to fix it. Here my program I try to do.
Thank you.
2 Comments
Torsten
on 20 Aug 2022
Edited: Torsten
on 20 Aug 2022
Accepted Answer
Paul
on 20 Aug 2022
If you're trying to store M1 for all values of n, then M1 needs to be 2 x 2 x n
M1(:,:,n) = [M1a(n) M1b(n);M1c(n) M1d(n)];
Consider preallocation of all the varaibles being assigned to.
4 Comments
Paul
on 21 Aug 2022
If M1 and M2 are both 2 x 2 x n, and M3 is 2 x 2 x n, and each page of M3 should be the product of the corresponding pages of M1 and M2, then use pagemtimes
M3 = pagemtimes(M1,M2)
M3 is now 2 x 2 x n. The (1,1) elements of the pages of M3 is then
M3a = M3(1,1,:);
M3a = squeeze(M3a); % or M3a = squeeze(M3(1,1,:))
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices 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!