Effacer les filtres
Effacer les filtres

Use elements from different Matrices as function input

1 vue (au cours des 30 derniers jours)
Fred John
Fred John le 31 Déc 2014
Commenté : Fred John le 31 Déc 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 commentaire
dpb
dpb le 31 Déc 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?

Connectez-vous pour commenter.

Réponse acceptée

Geoff Hayes
Geoff Hayes le 31 Déc 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

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by