Got Questions? Get Answers.
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:
data extraction from matrix to use in another matrix

Subject: data extraction from matrix to use in another matrix

From: walter Mulvany

Date: 19 Oct, 2013 16:03:06

Message: 1 of 27

I'm writing a code for finite element analysis and I don't know how to read a value from a matrix (A) and use it as a pointer to direct me to values in another matrix.
Here is a sample of the problem.
disp('Number of elements?')
    nelem=input('');
    connectivity=[1,1,2;2,1,3;3,2,3]
disp ('Elem # Node(a) Node(b)')
disp(connectivity)
    coordinates=[1,0,0;2,2,0;3,1,2]
disp ('Node # Xcoord Ycoord')
disp(coordinates)
disp('press enter to continue')
pause
for i= 1:nelem
    nodeax(i)=sscanf(connect(i,2));
    nodeaj(i)=sscanf(connect(i,2));
end
I need to read element's 1 node(a) which in this case is 1, and use that 1 to direct me to the node 1, extract the x and y coordinate from node 1, and create a matrix.

Thank you in advance for the help!

Subject: data extraction from matrix to use in another matrix

From: dpb

Date: 19 Oct, 2013 17:22:32

Message: 2 of 27

On 10/19/2013 11:03 AM, walter Mulvany wrote:
> I'm writing a code for finite element analysis and I don't know how to
> read a value from a matrix (A) and use it as a pointer to direct me to
> values in another matrix.
> Here is a sample of the problem.
...

> connectivity=[1,1,2;2,1,3;3,2,3]
...
> coordinates=[1,0,0;2,2,0;3,1,2]
...
> I need to read element's 1 node(a) which in this case is 1, and use that
> 1 to direct me to the node 1, extract the x and y coordinate from node
> 1, and create a matrix.
...

Well, it's not clear which you're after, but it's simple enough to find
a location in an array by value and get the associated information from
some other for that.

If ask for points in connectivity array that include node 1, that's given by

 >> conn=[1,1,2;2,1,3;3,2,3];
 >> coord=[1,0,0;2,2,0;3,1,2];
 >> idx=any(conn==1,2) % row indices of any connections w/ a '1'
idx =
      1
      1
      0
 >> coord(idx,:) % get those rows' coordinates...
ans =
      1 0 0
      2 2 0
 >> coord(any(conn==1,2),:) % do it w/o the intermediate variable
ans =
      1 0 0
      2 2 0
 >>

Look in subject index for "logical addressing" ...

--

Subject: data extraction from matrix to use in another matrix

From: walter Mulvany

Date: 19 Oct, 2013 18:30:08

Message: 3 of 27

dpb <none@non.net> wrote in message <l3uf4n$nm4$1@speranza.aioe.org>...
> On 10/19/2013 11:03 AM, walter Mulvany wrote:
> > I'm writing a code for finite element analysis and I don't know how to
> > read a value from a matrix (A) and use it as a pointer to direct me to
> > values in another matrix.
> > Here is a sample of the problem.
> ...
>
> > connectivity=[1,1,2;2,1,3;3,2,3]
> ...
> > coordinates=[1,0,0;2,2,0;3,1,2]
> ...
> > I need to read element's 1 node(a) which in this case is 1, and use that
> > 1 to direct me to the node 1, extract the x and y coordinate from node
> > 1, and create a matrix.
> ...
>
> Well, it's not clear which you're after, but it's simple enough to find
> a location in an array by value and get the associated information from
> some other for that.
>
> If ask for points in connectivity array that include node 1, that's given by
>
> >> conn=[1,1,2;2,1,3;3,2,3];
> >> coord=[1,0,0;2,2,0;3,1,2];
> >> idx=any(conn==1,2) % row indices of any connections w/ a '1'
> idx =
> 1
> 1
> 0
> >> coord(idx,:) % get those rows' coordinates...
> ans =
> 1 0 0
> 2 2 0
> >> coord(any(conn==1,2),:) % do it w/o the intermediate variable
> ans =
> 1 0 0
> 2 2 0
> >>
>
> Look in subject index for "logical addressing" ...
>
> --
Thank you for your input.
This program is supposed to work on a matrix of approximate 100 elements and what I'm looking for is that every time nodeax(i) iterate, it looks at the element (i), extract the value of the node (a), then with that value(ex: 3) it goes to the node 3 in the coordinates matrix and extract the (x) value of that node and creates nodeax matrix of size[2,nelem].
Again, thank you for your help, and sorry, but I don't have any experience programming and this is my first program.

Subject: data extraction from matrix to use in another matrix

From: dpb

Date: 19 Oct, 2013 18:37:05

Message: 4 of 27

On 10/19/2013 1:30 PM, walter Mulvany wrote:
> dpb <none@non.net> wrote in message <l3uf4n$nm4$1@speranza.aioe.org>...
>> On 10/19/2013 11:03 AM, walter Mulvany wrote:
>> > I'm writing a code for finite element analysis and I don't know how to
>> > read a value from a matrix (A) and use it as a pointer to direct me to
>> > values in another matrix.
>> > Here is a sample of the problem.
>> ...
>>
>> > connectivity=[1,1,2;2,1,3;3,2,3]
>> ...
>> > coordinates=[1,0,0;2,2,0;3,1,2]
>> ...
>> > I need to read element's 1 node(a) which in this case is 1, and use
>> that
>> > 1 to direct me to the node 1, extract the x and y coordinate from node
>> > 1, and create a matrix.
>> ...
>>
>> Well, it's not clear which you're after, but it's simple enough to
>> find a location in an array by value and get the associated
>> information from some other for that.
>>
>> If ask for points in connectivity array that include node 1, that's
>> given by
>>
>> >> conn=[1,1,2;2,1,3;3,2,3];
>> >> coord=[1,0,0;2,2,0;3,1,2];
>> >> idx=any(conn==1,2) % row indices of any connections w/ a '1'
>> idx =
>> 1
>> 1
>> 0
>> >> coord(idx,:) % get those rows' coordinates...
>> ans =
>> 1 0 0
>> 2 2 0
>> >> coord(any(conn==1,2),:) % do it w/o the intermediate variable
>> ans =
>> 1 0 0
>> 2 2 0
>> >>
>>
>> Look in subject index for "logical addressing" ...
>>
>> --
> Thank you for your input.
> This program is supposed to work on a matrix of approximate 100 elements
> and what I'm looking for is that every time nodeax(i) iterate, it looks
> at the element (i), extract the value of the node (a), then with that
> value(ex: 3) it goes to the node 3 in the coordinates matrix and extract
> the (x) value of that node and creates nodeax matrix of size[2,nelem].
> Again, thank you for your help, and sorry, but I don't have any
> experience programming and this is my first program.

Well, that's the same thing as just demonstrated --

coord(coord(nodeax(i)==i),1)

I'm not certain what you mean by "creates nodeax matrix of
size(2,nelem)", sorry...

--

Subject: data extraction from matrix to use in another matrix

From: walter Mulvany

Date: 19 Oct, 2013 23:42:06

Message: 5 of 27

My mistake, that matrix is wrong.
I tried what you suggested but I could not get it to work.
here is how the final matrix should look like.
Number of elements?
Elem # Node(a) Node(b)
     1 1 2
     2 2 3
     3 3 4
     4 4 7
     5 3 7
     6 3 6
     7 6 2
     8 5 2
     9 1 5
    10 5 6
    11 6 7

Node # X Y
     1 0 0
     2 2 0
     3 4 0
     4 6 0
     5 1 1
     6 3 1
     7 5 1

Final global matrix
Elem # Nodea Nodeb Nodeax Nodeay
     1 1 2 0 0
     2 2 3 2 0
     3 3 4 4 0
     4 4 7 6 0
     5 3 7 4 0
     6 3 6 4 0
     7 6 2 3 1
     8 5 2 1 1
     9 1 5 0 0
    10 5 6 1 1
    11 6 7 3 1

each element has a node(a) and (b), each node(a) have a x and a y coordinate, but some elements repeat the same node (a). As I said, I'm very new at Matlab and don't have experience programming.
Can you show me how to type it correctly so that it works?
I'm thinking to use a statement like this to do the iterations.

for i= 1:nelem
    nodeax(i)=
end

Subject: data extraction from matrix to use in another matrix

From: dpb

Date: 20 Oct, 2013 14:45:21

Message: 6 of 27

On 10/19/2013 6:42 PM, walter Mulvany wrote:
> My mistake, that matrix is wrong.
> I tried what you suggested but I could not get it to work.
> here is how the final matrix should look like.
> Number of elements?
> Elem # Node(a) Node(b)
> 1 1 2
> 2 2 3
> 3 3 4
...
> 10 5 6
> 11 6 7
>
> Node # X Y
> 1 0 0
> 2 2 0
> 3 4 0
...
> 7 5 1
>
> Final global matrix
> Elem # Nodea Nodeb Nodeax Nodeay
> 1 1 2 0 0
> 2 2 3 2 0
> 3 3 4 4 0
...
> 11 6 7 3 1
>
> each element has a node(a) and (b), each node(a) have a x and a y
> coordinate, but some elements repeat the same node (a). As I said, I'm
> very new at Matlab and don't have experience programming.
> Can you show me how to type it correctly so that it works?
...

Sure...using just the last two columns for the node/conn matrices
(there's no sense in storing a linear index as well; you can generate it
for display easily enough), then the result M is simply given by--

 >> M=zeros(length(conn),4); % preallocate (don't store the index)
 >> for i=1:length(conn),
      M(i,:)=[conn(i,:) node(conn(i,1),:)];
end
 >> M
M =
      1 2 0 0
      2 3 2 0
      3 4 4 0
      4 7 6 0
      3 7 4 0
      3 6 4 0
      6 2 3 1
      5 2 1 1
      1 5 0 0
      5 6 1 1
      6 7 3 1
 >>

--

Subject: data extraction from matrix to use in another matrix

From: walter Mulvany

Date: 20 Oct, 2013 15:40:07

Message: 7 of 27

Thank you very much dpq, you've been very helpful and I appreciate your patience with someone with no experience.
Hopefully I'll see you on the next roadblock of this program.

Subject: data extraction from matrix to use in another matrix

From: dpb

Date: 20 Oct, 2013 15:49:02

Message: 8 of 27

On 10/20/2013 10:40 AM, walter Mulvany wrote:
> Thank you very much dpq, you've been very helpful and I appreciate your
> patience with someone with no experience.
> Hopefully I'll see you on the next roadblock of this program.

As "exercise for the student", the previous can be written as a
one-liner with accumarray()... :)

--

Subject: data extraction from matrix to use in another matrix

From: walter Mulvany

Date: 21 Oct, 2013 00:23:11

Message: 9 of 27

I'm very sorry to say that it did not work because it arranged the matrices.
I need to go to matrix (connect) element 1, read node(a) and see that is a 4, because is the node 4, then I need to go the the matrix (coordinates), look for the node 4, and extract from node 4 the coordinate (x) and place it on an array nodeax.
repeat the process with all the elements.
As you can see, when the code reaches element 4, the node is 4 as well as element 1.
This has to be done for each of the elements from 1 to n (11) in this case.

  Elem (a) (b)
     1 4 2
     2 2 3
     3 3 4
     4 4 7
     5 3 7
     6 3 6
     7 6 2
     8 5 2
     9 1 5
    10 5 6
    11 6 7

 Node X Y
     1 0 0
     2 2 0
     3 4 0
     4 6 0
     5 1 1
     6 3 1
     7 5 1

The final matrix should look like this
Elem Nodea Nodeb Nodeax
     1 4 2 0 0
     2 2 3 2 0
     3 3 4 4 0
     4 4 7 6 0
     5 3 7 4 0
     6 3 6 4 0
     7 6 2 3 1
     8 5 2 1 1
     9 1 5 0 0
    10 5 6 1 1
    11 6 7 3 1
I hope I'm explaining it better now, I realize that I was not clear in the way I expressed the problem.
Thanks again for your time and for doing this for me.

Subject: data extraction from matrix to use in another matrix

From: dpb

Date: 21 Oct, 2013 02:42:55

Message: 10 of 27

> I'm very sorry to say that it did not work because it arranged the matrices.

It did precisely what your sample gave said to do...

> I need to go to matrix (connect) element 1, read node(a) and see
> that is a 4, because is the node 4, then I need to go the the matrix
(coordinates), look for the node 4, and extract from node 4 the
coordinate (x) and place it on an array nodeax.

Well, that makes no sense from the supposed output below where there's a
0 0 given for element 1 -- there's no 0 0 in the coord array for a node 4.

So, I don't think you've got what you want down precisely yet...

...

> Elem (a) (b)
> 1 4 2
> 2 2 3
...

> Node X Y
> 1 0 0
> 2 2 0
> 3 4 0
> 4 6 0
...
>
> The final matrix should look like this
> Elem Nodea Nodeb Nodeax
> 1 4 2 0 0
> 2 2 3 2 0
...

Try again, that doesn't seem to work to me.

Where, again, do you think the '0 0' come from for the first entry, now?

--

Subject: data extraction from matrix to use in another matrix

From: walter Mulvany

Date: 21 Oct, 2013 11:45:07

Message: 11 of 27

Elem # Nodea Nodeb Nodeax Nodeay
     1 4 2 6 0
     2 2 3 2 0
     3 3 4 4 0
     4 4 7 6 0
     5 3 7 4 0

You are right, element 1 should be (6 0), not (0 0), that was a typo, all the others are correct.

Subject: data extraction from matrix to use in another matrix

From: dpb

Date: 21 Oct, 2013 13:34:33

Message: 12 of 27

On 10/21/2013 6:45 AM, walter Mulvany wrote:
> Elem # Nodea Nodeb Nodeax Nodeay
> 1 4 2 6 0
> 2 2 3 2 0
> 3 3 4 4 0
> 4 4 7 6 0
> 5 3 7 4 0
>
> You are right, element 1 should be (6 0), not (0 0), that was a typo,
> all the others are correct.


So, it was correct as written...

 >> for i=1:length(conn),M(i,:)=[conn(i,:) Node(conn(i,1),:)];end
 >> M
M =
      4 2 6 0
      2 3 2 0
      3 4 4 0
      4 7 6 0
      3 7 4 0
      3 6 4 0
      6 2 3 1
      5 2 1 1
      1 5 0 0
      5 6 1 1
      6 7 3 1
 >>

--

Subject: data extraction from matrix to use in another matrix

From: dpb

Date: 21 Oct, 2013 16:28:59

Message: 13 of 27

On 10/21/2013 8:34 AM, dpb wrote:
> On 10/21/2013 6:45 AM, walter Mulvany wrote:
>> Elem # Nodea Nodeb Nodeax Nodeay
>> 1 4 2 6 0
>> 2 2 3 2 0
>> 3 3 4 4 0
>> 4 4 7 6 0
>> 5 3 7 4 0
>>
>> You are right, element 1 should be (6 0), not (0 0), that was a typo,
>> all the others are correct.
>
> So, it was correct as written...
>
> >> for i=1:length(conn),M(i,:)=[conn(i,:) Node(conn(i,1),:)];end
> >> M
> M =
> 4 2 6 0
> 2 3 2 0
> 3 4 4 0
> 4 7 6 0
> 3 7 4 0
...

Note, however, if you are looking for the is the location for which the
node is the _value_, the general idea still works but you need another
level of indirection to return the index of the location of a given
value...consider

M(i,:)=[conn(i,:) Node(find(Node(:,1)==conn(i,1)),:)];

and "salt to suit". I'm still not sure which it is you're trying to
build actually...but the former above reproduces the sample output; I'm
just not positive that's the output you need for the purpose.

--

Subject: data extraction from matrix to use in another matrix

From: walter Mulvany

Date: 21 Oct, 2013 22:10:17

Message: 14 of 27

I think that this problem is about indexing, and I don't think that I have done a good job explaining what I need to do.
This program is about finite element analysis of a bar element, and I have to input a number of nodes that have x,y coordinates, a number of member that have a connectivity between those nodes ( node a to node b or just columns 2 and 3 in matrix conn). Example, element 1 goes from node 5 to node 2, element 11 goes from node 6 to node 7.

What I need to do is to go to element 1, read the value of (conn - row 2) which is 5, go to the coord matrix, find the value (5) in its row 1 and extract the x value that correspond to that location (5) from (conn - row 2) which in this case is (1).

Those values can be stored in a matrix, lets call it M as you named it.
I think that the confusion came because I had the other matrices nodeax and nodeay and you probably thought that they existed as part of the input but I just put it there to show how the matrix with the coordinates look like.

conn=[1,5,2;2,2,3;3,3,4;4,4,7;5,3,7;6,3,6;7,6,2;8,5,2;9,1,5;10,5,6;11,6,7];
    disp ('Elem # Node(a) Node(b)')
    disp(conn)
coord=[1,0,0;2,2,0;3,4,0;4,6,0;5,1,1;6,3,1,;7,5,1];
    disp ('Node # Xcoord Ycoord')
    disp(coord)
    M=zeros(length(conn),4);
    for i=1:length(conn),
    M(i,:)=[conn(i,:) conn(find(conn(:,1)==conn(i,1)),:)];
    end

I apologize for all the confusion and I appreciate you effort.
Thanks.
Let me know if you need any additional information.

Subject: data extraction from matrix to use in another matrix

From: dpb

Date: 22 Oct, 2013 00:28:47

Message: 15 of 27

On 10/21/2013 5:10 PM, walter Mulvany wrote:
...

> What I need to do is to go to element 1, read the value of (conn - row
> 2) which is 5, go to the coord matrix, find the value (5) in its row 1
> and extract the x value that correspond to that location (5) from (conn
> - row 2) which in this case is (1).
>
> Those values can be stored in a matrix, lets call it M as you named it.
> I think that the confusion came because I had the other matrices nodeax
> and nodeay and you probably thought that they existed as part of the
> input but I just put it there to show how the matrix with the
> coordinates look like.
>
> conn=[1,5,2;2,2,3;3,3,4;4,4,7;5,3,7;6,3,6;7,6,2;8,5,2;9,1,5;10,5,6;11,6,7];
> coord=[1,0,0;2,2,0;3,4,0;4,6,0;5,1,1;6,3,1,;7,5,1];
...

> I apologize for all the confusion and I appreciate you effort.
> Thanks.
> Let me know if you need any additional information.

Well, yes, if the nodes that you were using weren't the actual inputs
then that does confuse things, indeed, since that's how you described
what it was you were looking to construct. I agree it didn't really
seem to make much sense but was just trying to do what was illustrated
as wanted.

Now then, if the node array is not there, let's take what _is_ and then
just the first 2 or three and then show what you're looking for as the
result -- it surely isn't clear to me why you start at element 1 and
then talk of row 2...??? Perhaps, even, you're mixing row w/ column as
there's no '5' in row 2 of conn but the value of row 1, col 2 is 5???

But, the idea of finding the location of a value in another array based
on the value instead of just the position was clearly demonstrated in
the last posting so if you do know which elements you're looking for it
shouldn't be too much to modify the previous example using the proper
arrays and indices.

But, if you can't get there from here, again straighten out the
nomenclature to get a description consistent with the data organization
and an example of the actual M desired for a small subset thereof...

--

Subject: data extraction from matrix to use in another matrix

From: walter Mulvany

Date: 22 Oct, 2013 00:49:07

Message: 16 of 27

yes, is column not row.

Subject: data extraction from matrix to use in another matrix

From: walter Mulvany

Date: 22 Oct, 2013 11:06:09

Message: 17 of 27

What I need to do is to go to element 1, read the value of (conn - column
> 2) which is 5, go to the coord matrix, find the value (5) in its column 1
> and extract the x value that correspond to that location (5) from (coord
> - column 2) which in this case is (1).
>
> Those values can be stored in a matrix, lets call it M as you named it.
When I do that I get this error

??? Subscripted assignment dimension mismatch.

Error in ==> trial at 13
    M(i,:)=[conn(i,:) conn(find(conn(:,1)==coord(i,1)),:)];

I know I have confused you a lot with my inexperience but if you can just give a last chance, I think that this is correct now. I've tried with other people at the university and nobody knows how to do it.

Subject: data extraction from matrix to use in another matrix

From: dpb

Date: 22 Oct, 2013 13:50:45

Message: 18 of 27

On 10/22/2013 6:06 AM, walter Mulvany wrote:
> What I need to do is to go to element 1, read the value of (conn - column
>> 2) which is 5, go to the coord matrix, find the value (5) in its column 1
>> and extract the x value that correspond to that location (5) from (coord
>> - column 2) which in this case is (1).
>>
>> Those values can be stored in a matrix, lets call it M as you named it.
> When I do that I get this error
> ??? Subscripted assignment dimension mismatch.
>
> Error in ==> trial at 13
> M(i,:)=[conn(i,:) conn(find(conn(:,1)==coord(i,1)),:)];
>
> I know I have confused you a lot with my inexperience but if you can
> just give a last chance, I think that this is correct now. I've tried
> with other people at the university and nobody knows how to do it.

It's not the inexperience that's confusing, it's that you don't
seemingly proofread what you write so what you say isn't what you
(apparently) mean. Like confounding rows and columns--if you would try
to work through the prescription you'd have found that there's a
dichotomy there--there was no '5' in the 2nd row...

Now if the above is to be believed, you don't need to "find" the element
in coord==5 because the first column as you've defined it is the same as
the index therefore the index to the row is actually the value you just
found.

Again, I suggest you _carefully_ work through your verbal descriptions
and refine them until you can actually solve the problem on paper first
-- then the code to implement that solution will fall out...or, at a
minimum as suggested, cut the size down to only 3 or so in the conn()
array so it all fits on a screen conveniently and show the inputs and
desired outputs and how they relate.

--

Subject: data extraction from matrix to use in another matrix

From: walter Mulvany

Date: 22 Oct, 2013 14:19:09

Message: 19 of 27

Thank you, I'll do that

Subject: data extraction from matrix to use in another matrix

From: walter Mulvany

Date: 22 Oct, 2013 14:54:07

Message: 20 of 27

What I need to do is to go to element 1, read the value of (conn - column 2) which is 5, go to the coord matrix, find the value (5) in its column 1 and extract the x value that correspond to that location (5) from (coord - column 2) which in this case is (1).

In other words, I have to connect the 2 matrices (conn and coord), and the result matrix have to contain conn plus the respective x , y values of each node a and b

conn=
Elem (a) (b)
1 5 2
2 2 3
3 3 4

coord=
Node x y
 1 0 0
 2 2 0
 3 4 0
 4 6 0
 5 1 1

The final matrix should look like this:

Elem From To ax ay bx by
1 5 2 1 1 2 0
2 2 3 2 0 4 0
3 3 4 4 0 6 0

I hope this is clear. Thanks.

Subject: data extraction from matrix to use in another matrix

From: dpb

Date: 22 Oct, 2013 16:59:16

Message: 21 of 27

On 10/22/2013 9:54 AM, walter Mulvany wrote:
> What I need to do is to go to element 1, read the value of (conn -
> column 2) which is 5, go to the coord matrix, find the value (5) in its
> column 1 and extract the x value that correspond to that location (5)
> from (coord - column 2) which in this case is (1).
>
> In other words, I have to connect the 2 matrices (conn and coord), and
> the result matrix have to contain conn plus the respective x , y values
> of each node a and b
>
...

> Elem From To ax ay bx by
> 1 5 2 1 1 2 0
> 2 2 3 2 0 4 0
> 3 3 4 4 0 6 0
>
> I hope this is clear. Thanks.

OK, now you've gotten a self-consistent description.

And as noted above, you don't need to do any lookup -- assuming the node
array is sequential and none missing it's simply an indirect reference.

Each M entry i is simply

  [conn(i,:) node(conn(i,2),2:end) node(conn(i,3),2:end)]

If you were to have missing nodes, simply add the additional level of
indirection previously illustrated with conn(i,2|3) being
find(node(:,1)==conn(i,2|3)) for the row index.

Again, NB that while the above keeps your use of the sequential column
vector in the first column of the two arrays, there's no reason at all
to store it unless you're going to allow the user to not specify all.

And, as previously mentioned, the above can be done w/o looping via
accumarray() -- I'll leave that as "exercise for the student"

 >> for i=1:length(conn)
   M(i,:)=[conn(i,:) Node(conn(i,2),2:end) Node(conn(i,3),2:end)];
   end
 >> M
M =
      1 5 2 1 1 2 0
      2 2 3 2 0 4 0
      3 3 4 4 0 6 0
      4 4 7 6 0 5 1
      5 3 7 4 0 5 1
      6 3 6 4 0 3 1
      7 6 2 3 1 2 0
      8 5 2 1 1 2 0
      9 1 5 0 0 1 1
     10 5 6 1 1 3 1
     11 6 7 3 1 5 1
 >>
--

Subject: data extraction from matrix to use in another matrix

From: walter Mulvany

Date: 22 Oct, 2013 17:24:08

Message: 22 of 27

I tried running it as you typed it and it gives me this error

?? Subscripted assignment dimension mismatch.

Error in ==> trial at 13
   M(i,:)=[conn(i,:) Node(conn(i,2),2:end) Node(conn(i,3),3:end)];

This is what I tried to run..

  disp('Number of elements?')
nelem=11;
conn=[1,5,2;2,2,3;3,3,4;4,4,7;5,3,7;6,3,6;7,6,2;8,5,2;9,1,5;10,5,6;11,6,7];
    disp ('Elem # Node(a) Node(b)')
    disp(conn)
Node=[1,0,0;2,2,0;3,4,0;4,6,0;5,1,1;6,3,1,;7,5,1];
    disp ('Node # Xcoord Ycoord')
    disp(Node)
    disp ('Elem # Nodea Nodeb Nodeax Nodeay')
    M=zeros(length(conn),4);
  for i=1:length(conn)
   M(i,:)=[conn(i,:) Node(conn(i,2),2:end) Node(conn(i,3),2:end)];
   end

Subject: data extraction from matrix to use in another matrix

From: dpb

Date: 22 Oct, 2013 17:33:10

Message: 23 of 27

On 10/22/2013 12:24 PM, walter Mulvany wrote:
> I tried running it as you typed it and it gives me this error
>
> ?? Subscripted assignment dimension mismatch.
>
> Error in ==> trial at 13
> M(i,:)=[conn(i,:) Node(conn(i,2),2:end) Node(conn(i,3),3:end)];
>
> This is what I tried to run..
>
...

> M=zeros(length(conn),4);
...

Again, proof your own work before crying wolf... :(

--

Subject: data extraction from matrix to use in another matrix

From: dpb

Date: 22 Oct, 2013 18:09:32

Message: 24 of 27

On 10/22/2013 12:33 PM, dpb wrote:
> On 10/22/2013 12:24 PM, walter Mulvany wrote:
>> I tried running it as you typed it and it gives me this error
>>
>> ?? Subscripted assignment dimension mismatch.
>>
>> Error in ==> trial at 13
>> M(i,:)=[conn(i,:) Node(conn(i,2),2:end) Node(conn(i,3),3:end)];
>>
>> This is what I tried to run..
>>
> ...
>
>> M=zeros(length(conn),4);
> ...
>
> Again, proof your own work before crying wolf... :(

That is, _think_ first, type second and don't try to just copy w/o
reading what it is and understanding what it's doing. How big is M as
you've now defined it?

--

Subject: data extraction from matrix to use in another matrix

From: walter Mulvany

Date: 22 Oct, 2013 18:14:07

Message: 25 of 27

Thank you thank you thank you!!!!!
You have no idea how much this means to me.
I've been struggling with this thing for days and it is mainly because I don't know enough about programming or Matlab, and while I'm trying to learn along the way the basics of it, I have a job, 4 kids and 19 credits, which 2 of the classes are masters level.
I really appreciate your patience with me.
I promise that next time I post something I'll triple proof it before I send it.
Again, thank you very much for your help.

Subject: data extraction from matrix to use in another matrix

From: dpb

Date: 22 Oct, 2013 18:45:41

Message: 26 of 27

On 10/22/2013 1:14 PM, walter Mulvany wrote:
> Thank you thank you thank you!!!!!
> You have no idea how much this means to me.
> I've been struggling with this thing for days and it is mainly because I
> don't know enough about programming or Matlab, and while I'm trying to
> learn along the way the basics of it, I have a job, 4 kids and 19
> credits, which 2 of the classes are masters level.
> I really appreciate your patience with me.
> I promise that next time I post something I'll triple proof it before I
> send it.
> Again, thank you very much for your help.

I also did a MS w/ kids and working fulltime so can relate.

But, I'll note your time will be much more effective if applied with
precision rather than "scatter-braining" and just trying to be fast.

As an old HS b-ball coach used to teach/preach --

"Play fast but don't hurry!"

There's a lot of wisdom both on and off the court in that...

--

Subject: data extraction from matrix to use in another matrix

From: dpb

Date: 22 Oct, 2013 20:57:31

Message: 27 of 27

On 10/22/2013 12:33 PM, dpb wrote:
> On 10/22/2013 12:24 PM, walter Mulvany wrote:
>> I tried running it as you typed it and it gives me this error
>>
>> ?? Subscripted assignment dimension mismatch.
>>
>> Error in ==> trial at 13
>> M(i,:)=[conn(i,:) Node(conn(i,2),2:end) Node(conn(i,3),3:end)];
>>
>> This is what I tried to run..
>>
> ...
>
>> M=zeros(length(conn),4);
> ...
>

ADDENDUM:

 >> M(i,:)=[conn(i,:) Node(conn(i,2),2:end) Node(conn(i,3),3:end)];

Should be

  M(i,:)=[conn(i,:) Node(conn(i,2),2:end) Node(conn(i,3),2:end)];

--

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