The Math Forum

Search All of the Math Forum:

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

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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  

Posts: 2,359
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 " <> wrote in message <kg362o$6eh$>...
> 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:


for more info.

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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.