reshape matrix with diffrent size

1 次查看(过去 30 天)
Hi
i have a matrix with 3 column X,Y Z
vecteur =[ 0 0 0
0 0.05 0
0 0.1 0
0 0.15 0
0 0.2 0
0 0.25 0
0 0.3 0
0 0.35 0
0 0.4 0
0 0.45 0
0 0.5 0
0 0.55 0
0 0.6 0
0 0.65 0
0 0.7 0
0 0.75 0
0 0.8 0
0 0.85 0
0 0.9 0
0 0.95 0
0 1 0
0.05 0 0
0.05 0.1 -0.015386
0.05 0.2 -0.029267
0.05 0.3 -0.040282
0.05 0.4 -0.047355
0.05 0.5 -0.049792
0.05 0.6 -0.047355
0.05 0.7 -0.040282
0.05 0.8 -0.029267
0.05 0.9 -0.015386
0.05 1 0
0.1 0 0
0.1 0.05 -0.015387
0.1 0.1 -0.030392
0.1 0.15 -0.044653
0.1 0.2 -0.057809
0.1 0.25 -0.069549
0.1 0.3 -0.079567
0.1 0.35 -0.087637
0.1 0.4 -0.093536
0.1 0.45 -0.097147
0.1 0.5 -0.09835
0.1 0.55 -0.097147
0.1 0.6 -0.093536
0.1 0.65 -0.087637
0.1 0.7 -0.079567
0.1 0.75 -0.069549
0.1 0.8 -0.057809
0.1 0.85 -0.044653
0.1 0.9 -0.030392
0.1 0.95 -0.015387
0.1 1 0
0.15 0 0
0.15 0.1 -0.044653
0.15 0.2 -0.084935
0.15 0.3 -0.1169
0.15 0.4 -0.13743
0.15 0.5 -0.1445
0.15 0.6 -0.13743
0.15 0.7 -0.1169
0.15 0.8 -0.084935
0.15 0.9 -0.044653
0.15 1 0
0.2 0 0
0.2 0.05 -0.029267
0.2 0.1 -0.057809
0.2 0.15 -0.084936
0.2 0.2 -0.10996
0.2 0.25 -0.13229
0.2 0.3 -0.15134
0.2 0.35 -0.1667
0.2 0.4 -0.17792
0.2 0.45 -0.18478
0.2 0.5 -0.18707
0.2 0.55 -0.18478
0.2 0.6 -0.17792
0.2 0.65 -0.1667
0.2 0.7 -0.15134
0.2 0.75 -0.13229
0.2 0.8 -0.10996
0.2 0.85 -0.084936
0.2 0.9 -0.057809
0.2 0.95 -0.029267
0.2 1 0
0.25 0 0
0.25 0.1 -0.069549
0.25 0.2 -0.13229
0.25 0.3 -0.18208
0.25 0.4 -0.21405
0.25 0.5 -0.22507
0.25 0.6 -0.21405
0.25 0.7 -0.18208
0.25 0.8 -0.13229
0.25 0.9 -0.069549
0.25 1 0
0.3 0 0
0.3 0.05 -0.040282
0.3 0.1 -0.079567
0.3 0.15 -0.1169
0.3 0.2 -0.15134
0.3 0.25 -0.18208
0.3 0.3 -0.20831
0.3 0.35 -0.22944
0.3 0.4 -0.24488
0.3 0.45 -0.25433
0.3 0.5 -0.25748
0.3 0.55 -0.25433
0.3 0.6 -0.24488
0.3 0.65 -0.22944
0.3 0.7 -0.20831
0.3 0.75 -0.18208
0.3 0.8 -0.15134
0.3 0.85 -0.1169
0.3 0.9 -0.079567
0.3 0.95 -0.040282
0.3 1 0
0.35 0 0
0.35 0.1 -0.087637
0.35 0.2 -0.1667
0.35 0.3 -0.22944
0.35 0.4 -0.26972
0.35 0.5 -0.2836
0.35 0.6 -0.26972
0.35 0.7 -0.22944
0.35 0.8 -0.1667
0.35 0.9 -0.087637
0.35 1 0
0.4 0 0
0.4 0.05 -0.047355
0.4 0.1 -0.093536
0.4 0.15 -0.13743
0.4 0.2 -0.17792
0.4 0.25 -0.21405
0.4 0.3 -0.24488
0.4 0.35 -0.26972
0.4 0.4 -0.28788
0.4 0.45 -0.29899
0.4 0.5 -0.30269
0.4 0.55 -0.29899
0.4 0.6 -0.28788
0.4 0.65 -0.26972
0.4 0.7 -0.24488
0.4 0.75 -0.21405
0.4 0.8 -0.17792
0.4 0.85 -0.13743
0.4 0.9 -0.093536
0.4 0.95 -0.047355
0.4 1 0
0.45 0 0
0.45 0.1 -0.097146
0.45 0.2 -0.18478
0.45 0.3 -0.25433
0.45 0.4 -0.29899
0.45 0.5 -0.31437
0.45 0.6 -0.29899
0.45 0.7 -0.25433
0.45 0.8 -0.18478
0.45 0.9 -0.097146
0.45 1 0
0.5 0 0
0.5 0.05 -0.049792
0.5 0.1 -0.09835
0.5 0.15 -0.1445
0.5 0.2 -0.18707
0.5 0.25 -0.22507
0.5 0.3 -0.25748
0.5 0.35 -0.2836
0.5 0.4 -0.30269
0.5 0.45 -0.31437
0.5 0.5 -0.31827
0.5 0.55 -0.31437
0.5 0.6 -0.30269
0.5 0.65 -0.2836
0.5 0.7 -0.25748
0.5 0.75 -0.22507
0.5 0.8 -0.18707
0.5 0.85 -0.1445
0.5 0.9 -0.09835
0.5 0.95 -0.049792
0.5 1 0
0.55 0 0
0.55 0.1 -0.097146
0.55 0.2 -0.18478
0.55 0.3 -0.25433
0.55 0.4 -0.29899
0.55 0.5 -0.31437
0.55 0.6 -0.29899
0.55 0.7 -0.25433
0.55 0.8 -0.18478
0.55 0.9 -0.097146
0.55 1 0
0.6 0 0
0.6 0.05 -0.047355
0.6 0.1 -0.093536
0.6 0.15 -0.13743
0.6 0.2 -0.17792
0.6 0.25 -0.21405
0.6 0.3 -0.24488
0.6 0.35 -0.26972
0.6 0.4 -0.28788
0.6 0.45 -0.29899
0.6 0.5 -0.30269
0.6 0.55 -0.29899
0.6 0.6 -0.28788
0.6 0.65 -0.26972
0.6 0.7 -0.24488
0.6 0.75 -0.21405
0.6 0.8 -0.17792
0.6 0.85 -0.13743
0.6 0.9 -0.093536
0.6 0.95 -0.047355
0.6 1 0
0.65 0 0
0.65 0.1 -0.087637
0.65 0.2 -0.1667
0.65 0.3 -0.22944
0.65 0.4 -0.26972
0.65 0.5 -0.2836
0.65 0.6 -0.26972
0.65 0.7 -0.22944
0.65 0.8 -0.1667
0.65 0.9 -0.087637
0.65 1 0
0.7 0 0
0.7 0.05 -0.040282
0.7 0.1 -0.079567
0.7 0.15 -0.1169
0.7 0.2 -0.15134
0.7 0.25 -0.18208
0.7 0.3 -0.20831
0.7 0.35 -0.22944
0.7 0.4 -0.24488
0.7 0.45 -0.25433
0.7 0.5 -0.25748
0.7 0.55 -0.25433
0.7 0.6 -0.24488
0.7 0.65 -0.22944
0.7 0.7 -0.20831
0.7 0.75 -0.18208
0.7 0.8 -0.15134
0.7 0.85 -0.1169
0.7 0.9 -0.079567
0.7 0.95 -0.040282
0.7 1 0
0.75 0 0
0.75 0.1 -0.069549
0.75 0.2 -0.13229
0.75 0.3 -0.18208
0.75 0.4 -0.21405
0.75 0.5 -0.22507
0.75 0.6 -0.21405
0.75 0.7 -0.18208
0.75 0.8 -0.13229
0.75 0.9 -0.069549
0.75 1 0
0.8 0 0
0.8 0.05 -0.029267
0.8 0.1 -0.057809
0.8 0.15 -0.084936
0.8 0.2 -0.10996
0.8 0.25 -0.13229
0.8 0.3 -0.15134
0.8 0.35 -0.1667
0.8 0.4 -0.17792
0.8 0.45 -0.18478
0.8 0.5 -0.18707
0.8 0.55 -0.18478
0.8 0.6 -0.17792
0.8 0.65 -0.1667
0.8 0.7 -0.15134
0.8 0.75 -0.13229
0.8 0.8 -0.10996
0.8 0.85 -0.084936
0.8 0.9 -0.057809
0.8 0.95 -0.029267
0.8 1 0
0.85 0 0
0.85 0.1 -0.044653
0.85 0.2 -0.084935
0.85 0.3 -0.1169
0.85 0.4 -0.13743
0.85 0.5 -0.1445
0.85 0.6 -0.13743
0.85 0.7 -0.1169
0.85 0.8 -0.084935
0.85 0.9 -0.044653
0.85 1 0
0.9 0 0
0.9 0.05 -0.015387
0.9 0.1 -0.030392
0.9 0.15 -0.044653
0.9 0.2 -0.057809
0.9 0.25 -0.069549
0.9 0.3 -0.079567
0.9 0.35 -0.087637
0.9 0.4 -0.093536
0.9 0.45 -0.097147
0.9 0.5 -0.09835
0.9 0.55 -0.097147
0.9 0.6 -0.093536
0.9 0.65 -0.087637
0.9 0.7 -0.079567
0.9 0.75 -0.069549
0.9 0.8 -0.057809
0.9 0.85 -0.044653
0.9 0.9 -0.030392
0.9 0.95 -0.015387
0.9 1 0
0.95 0 0
0.95 0.1 -0.015386
0.95 0.2 -0.029267
0.95 0.3 -0.040282
0.95 0.4 -0.047355
0.95 0.5 -0.049792
0.95 0.6 -0.047355
0.95 0.7 -0.040282
0.95 0.8 -0.029267
0.95 0.9 -0.015386
0.95 1 0
1 0 0
1 0.05 0
1 0.1 0
1 0.15 0
1 0.2 0
1 0.25 0
1 0.3 0
1 0.35 0
1 0.4 0
1 0.45 0
1 0.5 0
1 0.55 0
1 0.6 0
1 0.65 0
1 0.7 0
1 0.75 0
1 0.8 0
1 0.85 0
1 0.9 0
1 0.95 0
1 1 0];
and i want to plot surf or contour or mesh with interpolation
a want this forme
i try this
X=vecteur(:,1);
Y=vecteur(:,2);
Z=vecteur(:,3);
GNN=length(X);
[xx,yy]=meshgrid(X,Y);
axis_x = -1/2:.02:1/2;
axis_y = -1/2:.02:1/2;
[xxx,yyy] = meshgrid(axis_x,axis_y);
Vect_zero = zeros(GNN,GNN);
% i know that i must use reshape for vector Z , but i dont know how
% cause Z is not reggulaire , sometime is 19 betwin 2 zero and somtimes 9 betwin 2 zero
% so i dont know how can i use N or reshape
Vect_zero = reshape(Z,N,N);
% i need to interpolate
Vect_interpol = interp2(xx,yy,Vect_zero,xxx,yyy,'cubic');
contour(axis_x,axis_y,Vect_interpol,-0.9:0.2:0.9);
or meshc(xxx,yyy,Vect_interpol);
someone can help
please

采纳的回答

Voss
Voss 2022-12-3
load('vecteur.mat') % stored vecteur in a mat file, to avoid defining it in the code again here
SI = scatteredInterpolant(vecteur(:,1),vecteur(:,2),vecteur(:,3));
[X,Y] = meshgrid(unique(vecteur(:,1)),unique(vecteur(:,2)));
surf(X,Y,SI(X,Y))
  3 个评论
Voss
Voss 2022-12-3
You're welcome!
scatteredInterpolant is good to use in this case, since the x- and y-coordinates have that irregular behavior (i.e., "sometime is 19 betwin 2 zero and somtimes 9 betwin 2 zero").

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by