필터 지우기
필터 지우기

Matrix as input argument of a matlab function

조회 수: 179 (최근 30일)
Bijoy
Bijoy 2013년 6월 17일
I want to pass two matrices A and B as input arguments to a function. but I am getting the error "Not enough input argument" I tried a simple function as follows but still I am getting the same error,
function [ C ] = add( A, B )
%ADD TWO MATRICES A AND B
C=A+B;
end

채택된 답변

John
John 2013년 6월 17일
Are you calling the function from your command window, or are you just hitting "run" in your editor? From the command window, the function works fine for me.
  댓글 수: 3
Jan
Jan 2013년 6월 18일
The "run" button does not define input arguments in the default setup - how could it. So using this function from another script, function or the command window will work with C = add(A, B).
John
John 2013년 6월 18일
To call the function from another script you might need to add something like this to the top of that script:
addpath(genpath('C:\whereyourfunctionissaved'));
also it needs to be saved as add.m
Sounds like your problem is that you're using the run button- that doesn't work.

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

추가 답변 (2개)

James Tursa
James Tursa 2013년 6월 17일
How are you calling the function? E.g., are you doing this:
A = rand(2,2); % sample data
B = rand(2,2); % sample data
C = add(A,B);

Roger Stafford
Roger Stafford 2013년 6월 17일
Check that you don't have another function named 'add' on your system that calls for more than two inputs and is being mistakenly called instead of your current 'add' function.
  댓글 수: 2
Bijoy
Bijoy 2013년 6월 18일
I don't think so.
Jan
Jan 2013년 6월 18일
Thinking is less helpful as asking Matlab for a precise answer:
which add -all

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

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by