Use elements from different Matrices as function input
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Fred John
am 31 Dez. 2014
Kommentiert: Fred John
am 31 Dez. 2014
Hi
I previously asked a question which was resolved here:
My follow up question is: how can I use an element from a different Matrix (B2(1,1) & B2(1,2)) at the same time?
My guess was
i
function [S] = myFunction(A,B)
q=A(1,1);
w=A(1,2);
h=B2(1,1);
k=B2(1,2);
Can someone help or verify? Thanks!
1 Kommentar
dpb
am 31 Dez. 2014
Don't follow the question, precisely? Of course you can associate any element of any array with a temporary variable as you've outlined, but why not just use the reference directly?
Answering my own (admittedly somewhat rhetorical) question, there is one reason in that it's less typing to use the single-character variable names or there may be a physical interpretation of the elements such that it's convenient for documentation purposes of reading the code. But, it's immaterial as far as Matlab is concerned.
So, again, what's the real issue behind the question?
Akzeptierte Antwort
Geoff Hayes
am 31 Dez. 2014
Fred - you have the right idea. If you want to use data from both A and B, then pass them both as input parameters to your function and access the data like you have done (except use B instead of B2)
function [S] = myFunction(A,B)
q=A(1,1);
w=A(1,2);
h=B(1,1);
k=B(1,2);
S = [];
% set S with q, w, h, and k
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!