From: Vinz Vega on
Hello,

this is a very basic question, I am almost ashamed of asking but I would really like to know this.

What I'd like to do is to index the ans I get from querying the size of an array, employing one line only.

Since I don't know how to do that, I usually do this:

>>dumb=size(A)
>>dumb(2)
ans=
x

or
>>[row, col]=size(A)
>>col
ans=
x

stuff like:
>>size(A)(2)

obviously return typographic errors.

As an example, it'd be nice to increase a matrix dimension in a loop based on its current size, like:

for n=1:x
A(length(A)+1)= n

How can I do that for any dimension, not just max(size)?

Thanks a lot.
vinz
From: us on
"Vinz Vega" <aspettiamogodot(a)fastwebnet.it> wrote in message <hu0a9v$2rj$1(a)fred.mathworks.com>...
> Hello,
>
> this is a very basic question, I am almost ashamed of asking but I would really like to know this.
>
> What I'd like to do is to index the ans I get from querying the size of an array, employing one line only.
>
> Since I don't know how to do that, I usually do this:
>
> >>dumb=size(A)
> >>dumb(2)
> ans=
> x
>
> or
> >>[row, col]=size(A)
> >>col
> ans=
> x
>
> stuff like:
> >>size(A)(2)
>
> obviously return typographic errors.
>
> As an example, it'd be nice to increase a matrix dimension in a loop based on its current size, like:
>
> for n=1:x
> A(length(A)+1)= n
>
> How can I do that for any dimension, not just max(size)?
>
> Thanks a lot.
> vinz

see what happens with
one of the very(!) bad solutions

m=[];
for i=1:3
m(end+1:end+2,end+1:end+2)=i;
end
disp(m);

us
From: sscnekro on
Hi Vinz Vega,

it is not really clear to me what you are looking for, but I fancy there are two questions in fact.

As for the first, I fancy you ask about
A = zeros(5,8);
size(A,2)
ans =
8

but I am not sure if this really helps to solve the second problem. Do you need just to increase your A matrix alongside the column dimension, or do you want to increase A by concatenating certain column vectors?
A = [A, something(:,1)]; % update A

PS From own experience I know that it's always wise to listen to us. Even those of his replies to my posts he himself tagged as "humour" made me to get it to the solution. Good luck.
From: ImageAnalyst on
How about
A = [A 1:x]
That will do what your for loop is doing.

As far as indexing ans . . . why? You already have dumb() and you can
index that.
From: sscnekro on
> A = [A, something(:,1)]; % update A

Sorry, typo:
something .. < size(A,1) x 1>
A = [A, something]; % update A
 |  Next  |  Last
Pages: 1 2 3
Prev: MATLAB LOOP
Next: Read a huge text file in MATLAB