Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: variable number of inputs of a function
Replies: 1   Last Post: Feb 20, 2013 2:42 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Curious

Posts: 1,983
Registered: 12/6/04
Re: variable number of inputs of a function
Posted: Feb 20, 2013 2:42 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"vijay " <vijaybrcm@rediffmail.com> wrote in message <kg362o$6eh$1@newscl01ah.mathworks.com>...
> function []=mainprog()
> clc
> len=5
>
> for i=1:len
> eval(['scalar', num2str(i), '= randi(10,1,3)']);
> end
> rqarray=[10,20,30,40,50]
> weighted=weightedimage(scalar,rqarray)
>
>
> function weighted=weightedimage(scalar,rqarray);
> for i=1:len
> w=rqarray(1,i)
> J=w*[scalar]
> allzero=zeros(1,3)
> wfinal=allzero+w
> Jfinal=allzero+J
> end
> weighted=Jfinal./wfinal
>
>
>
>
> In this program in the function weightedimage, how we should write input named as scalar. if i write it as scalar it gives error.


What error message does it give you?

I don't have MATLAB installed on this computer, but in general, I would avoid using scalar as a variable. It may be a keyword reserved by MATLAB. Try changing scalar to something like Scalar, scAlar, or something else and see if that works. Also, you should avoid using eval in the above code. Use cell arrays instead. Simply:

scalar1{i} = randi(10,1,3);

should work.

See the MATLAB FAQ at:

<<http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F>>

for more info.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.