Use elements from different Matrices as function input
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
dpb
2014-12-31
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?
采纳的回答
Geoff Hayes
2014-12-31
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!