Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
how to do this?

Subject: how to do this?

From: Alex

Date: 23 Jun, 2011 20:08:04

Message: 1 of 2

The following creates a matrix, then breaks it into lines, so that I can send each line as a vector to a function. I dont know if this is the best way, but it seems to work (Generally) However if any of the values in the matrix (array) are greater than 9, i.e double figures, it causes an error. Why? and what is there to fix it.

Thanks Guys

Alex

clear
  array = [1,2,3;4,5,6;7,8,9]

    openb=('[');
    closeb = (']');
    for ii = 1:length(array);

          vv = sprintf('%s',num2str(array(ii,:)))
            finalstring(ii,:) = strcat(openb,vv, closeb)
    % finalnums(ii,:) = str2num(finalstring(ii,:));
    % varargin{ii} = finalnums(ii,:);
     end

The problem is the information has to be passed to the other function in the form of vectors.

the function is called allcomb:

allcomb([1 2],[3 4],[5 6])
The vectors above are the rows in my matrix

How do I pass them if I dont always know how big they will be?
Thanks

Subject: how to do this?

From: dpb

Date: 23 Jun, 2011 21:04:16

Message: 2 of 2

Alex wrote:

> The following creates a matrix, then breaks it into lines, so that I can
> send each line as a vector to a function. I dont know if this is the
> best way, ...



Almost certainly _not_ the best way...

...


> array = [1,2,3;4,5,6;7,8,9]
...


> The problem is the information has to be passed to the other function in
> the form of vectors.
>
> the function is called allcomb:
>
> allcomb([1 2],[3 4],[5 6])
> The vectors above are the rows in my matrix
...


Well, [1 2], etc., are _NOT_ the rows of the matrix array you gave
above...those are vectors of length 3, not 2.

What would be wrong w/

a) Passing the rows as array(1,:), array(2,:), etc., ...,

or, since that is still really ugly for an arbitrary size array,

b) Write the function to accept an array and have it inspect the size of
the array and do whatever it is that it does dynamically based on that?

Let's go back a step instead of working on this kludge and tell us what
you're trying to accomplish and get input from cs-sm on the way to
accomplish that goal instead.

--

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us