필터 지우기
필터 지우기

pass big matrices into function

조회 수: 2 (최근 30일)
fatema saba
fatema saba 2014년 6월 24일
댓글: dpb 2014년 6월 24일
Hello My question is very simple How can pass many big matrices into function. for example my function is:
f=[B(:);C(:);D(:);E(:);G(;)]
B, C, D, E and G are (1045*942) matrices. I can't write again them in function. I created these matrices before and I want to pass them into function only by name.
How can I do it?

답변 (2개)

dpb
dpb 2014년 6월 24일
function outputs=yourfunction(B,C,D,E,G)
% do whatever to compute outputs with the input arrays
Matlab syntax doesn't care about size or even types of arguments; just refer to them as the variable names and all the rest takes care of itself.
See
doc function
for more details on writing functions in Matlab
  댓글 수: 2
fatema saba
fatema saba 2014년 6월 24일
Sorry I can't understand. for example my function is:
function[f]= ave2(B,C) f=[B(:);C(:)] end
and I created matrix B and C before. when I ran ave2 in MaTlab I got this error:
Input argument "B" is undefined.
dpb
dpb 2014년 6월 24일
Sorry, you're not providing anything near enough information to tell what went wrong. Show the complete code and the code you ran as you ran it, precisely.
If you have a function in an m-file that consists of
function[f]= ave2(B,C)
f=[B(:);C(:)]
end
Then you call it just like any other Matlab function as (in the calling script or at the command line) --
x=rand(3);
y=rand(5);
z=ave2(x,y);
In this case you would get a returned vector z of length 34 (9+25). Inside the function B would be equated to x and C to y.

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2014년 6월 24일
You could have just tried. But don't worry about it - they're not very big. Even 5 of them is not very big at all.

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by