Inserting a row in a matrix defined by a vector?

Hi guys!
I am fairly new to matlab - actually just atarted using it on my bachelor this monday :)
I'm trying to make a 8x3 matrix containing the displacement in each DOF output from a finite element calculation, that I am trying to make generel.
But when i want to plot the result on a plot of the original frame/truss the matrix sizes does not match obviously.
I have a 8x2 matrix containing the x and y input coordinates, which I can plot easily. But i only get displacements in a 5x2 matrix because 3 of the nodes are fixed, and not included in the stiffness matrix used to compute the displacement output.
To make the plot i need to be able to automatic generate 3 rows of zeros in my output matrix on the positions where the fixed support output is missing.
Get it?
Like this:
Node coordinates:
(x y) =
[0 0,
0 1,
1 1,
2 1,
2 0,
3 1,
4 1,
4 0]
Fixed nodes: [1 5 8]
Which after a couple of calculations gives me the right displacement output but only in the free nodes.
Fictional output(x,y) = [ 2 2 , 3 3 , 4 4 , 6 6 , 7 7 ]
But to plot the output i need a matrix sized 8x2 instead of 5x2. So i need an automated way to put a row of zeros on the place of every fixed node, so i end up with af automated output like this:
New output(x,y) = [ 0 0 , 2 2 , 3 3 , 4 4 , 0 0 , 6 6 , 7 7 , 8 8 ]
But generated direcly from the fixed node vector! I can make the matrix by changing it manually, but i cannot seem to make it automated.
Can anyone help?

 Respuesta aceptada

Star Strider
Star Strider el 7 de Mayo de 2015
This seems to work:
FictionalMatrix = [2 2; 3 3; 4 4; 6 6; 7 7];
FixedNodes = [1 5 8];
NewOutput = zeros(8,2);
NewOutput(setdiff(1:8,FixedNodes),:) = FictionalMatrix;

Más respuestas (1)

Nicklas Olling
Nicklas Olling el 7 de Mayo de 2015

0 votos

Thank you! Worked like a charm!

Categorías

Preguntada:

el 7 de Mayo de 2015

Comentada:

el 7 de Mayo de 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by