Plot 2d and 3d Matrix

5 visualizzazioni (ultimi 30 giorni)
Andrea Hern{andez
Andrea Hern{andez il 17 Ott 2017
Commentato: Walter Roberson il 19 Ott 2017
Hi! I have 2 matrix. One is a 2180x10 matrix (pressure) and the other is a 2180x10x3 matrix ( deformation in the x,y,z coordinates). I want to plot pressure (2d matrix) in funtion of de deformation (3d matrix). How could I do it?

Risposte (1)

Walter Roberson
Walter Roberson il 18 Ott 2017
It was a bit tricky to figure out a meaningful way to plot that. I had to assume that you are starting with an X Y grid with originally constant Z, and deformation is taking place at each point, and the deformation is moving the nodes a bit in the X, Y, and Z directions. In order to plot, I had to assume that the deformation array gives the relative movement on the node positions, and that you wanted to plot the pressure at the final position of each node.
%create test data. These are not expected to have anything to do with
%your real data, but I needed *some* data of the right size to experiment with
deformation = sort( rand(2810, 10, 3)/10 );
[px, py] = ndgrid(linspace(-3,3,2810), linspace(-3,3,10));
pressure = 3*(1-px).^2.*exp(-(px.^2) - (py+1).^2) ...
- 10*(px/5 - px.^3 - py.^5).*exp(-px.^2-py.^2) ...
- 1/3*exp(-(px+1).^2 - py.^2);
%now do the drawing
dx = deformation(:,:,1);
dy = deformation(:,:,2);
dz = deformation(:,:,3);
nrow = size(dx,1);
ncol = size(dx,2);
[X, Y] = ndgrid(1:nrow, 1:ncol);
X = X + dx;
Y = Y + dy;
Z = dz;
surf(X, Y, Z, pressure, 'edgecolor', 'none')
If, instead, your deformation array is already the absolute positions that each node ends up at, then it could be as simple as:
X = deformation(:,:,1);
Y = deformation(:,:,2);
Z = deformation(:,:,3);
surf(X, Y, Z, pressure, 'edgecolor', 'none')
  4 Commenti
Walter Roberson
Walter Roberson il 19 Ott 2017
You have
a=load('presion.txt');
p=a(:,2);
p(21802:21810)=2.03;
m=length(p)/10;%number of rows
a is length 21802; you copy that and you specifically set up to entry 21810 of the result. Then you divide the length of that by 10, getting 2181 .
Note: the code that follows,
pressure=zeros(m,n);
%iteracion para formar matriz de 10 columna
while i<=length(a)
for k=1:n
for j=1:m
pressure(j,k)=p(i);
i=i+1;
end
end
end
could instead be written:
pressure = reshape(p, m, n);
pressure(length(a)+1:end) = 0;
pressure(21802) = 2.03;
This leads to the question of why you bothered with
p=a(:,2);
p(21802:21810)=2.03;
as p will never be used after it is copied into pressure and the entries from length(a)+1 to 21810 are going to be ignored. Unless, that is, that you are trying to account for the possibility that a is 21802 or longer and the entries starting from 21802 need to be set to 2.03 ??? If you are expecting variable length a, then what if it is more than 21810 long?
Anyhow, after that you have
b=load('deformacion.txt');
x=b(:,1); %x coordinate
y=b(:,2); %y coordinate
z=b(:,3); %z coordinate
x(21796:21800)=-5.29325;
y(21796:21800)=-7.553305;
z(21796:21800)=721.812683;
m=length(x)/10; %numer of rows
b is 21795 long, and you set the entries after that to 21800 to fixed values, and divide the length by 10, which is going to give you m = 2180 (unless the deformation file might have had more than 21800 entries.)
So now you have a problem: your pressure matrix is 2181 rows long, but your coordinate definitions are 2180 long, one row shorter.
How do you want to handle this situation?

Accedi per commentare.

Categorie

Scopri di più su Discrete Data Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by