MATLAB Answers

Matrix as input argument of a matlab function

434 views (last 30 days)
Bijoy
Bijoy on 17 Jun 2013
Answered: Ajith Thomas on 20 Jun 2019
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

  0 Comments

Sign in to comment.

Accepted Answer

John
John on 17 Jun 2013
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 Comments

Bijoy
Bijoy on 18 Jun 2013
At the time of executing the function itself by hitting the "run" in the editor where I wrote the function. I want to call this function in another script.
Jan
Jan on 18 Jun 2013
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 on 18 Jun 2013
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.

Sign in to comment.

More Answers (5)

Antonio Pascual Esono Ndong
function [top_left, top_right, bottom_left, bottom_right]= corner(x)
top_left= x(1,1);
top_right= x(1,end);
bottom_left= x(end,1);
bottom_rigth= x(end, end);
end

  0 Comments

Sign in to comment.


James Tursa
James Tursa on 17 Jun 2013
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 on 17 Jun 2013
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 Comments

Jan
Jan on 18 Jun 2013
Thinking is less helpful as asking Matlab for a precise answer:
which add -all

Sign in to comment.


Ajith Thomas
Ajith Thomas on 4 Apr 2019
Write a function called corners that takes a matrix as an input argument and returns four outputs: the elements at its four corners in this order: top_left, top_right, bottom_left and bottom_right. (Note that loops and if-statements are neither necessary nor allowed as we have not covered them yet.) how to resolve this question? can anyone answer?

  0 Comments

Sign in to comment.


Ajith Thomas
Ajith Thomas on 20 Jun 2019
Thanks for your valuable feedback. can I ask few questions more?

  0 Comments

Sign in to comment.

Tags


Translated by