# How to arrange coordinates into 3 columns?

11 views (last 30 days)
Oscar Espinosa on 15 Aug 2019
Commented: Rik on 15 Aug 2019
I'm creating the mesh of a wing, so, in order to export the coordinates of each node I need to arrange all the coordinates (x,y,z) into three columns.
By the moment I have agrouped the coordinates into three section, each one correspont to each coordinate. But I would like to organize them in such a way that each column continues to be a single column until the last one corresponding to that coordinate (x or y or z). I hope I have explained myself, I also attached an image and the code.Thanks in advance function WINGEODISC
FILEID = fopen('A_prof.txt','r');
FORMATSPEC = '%f %f'; % %d times should correspont to m
SIZEXZ = [3 Inf]; % [m,n] n can be Inf, but m cannot.
XZ = fscanf(FILEID,FORMATSPEC,SIZEXZ);
fclose(FILEID);
XZ = XZ';
XP_AIRFOIL = XZ(:,1);
ZP_AIRFOIL = XZ(:,2);
%% Wing definitions
MAIN_NODES_X = ones(4,4);
%SPAN = 10;
AREA = 7.5;
AR = 13.3333;
LE_SWEPT = 30; % Swept wing - Стреловидность - Flechamiento [deg]
%TE_SWEPT = 0; % Trailing edge
TAPER = 2;
SEMISPAN = sqrt(AR*AREA)/2;
CHORD_ROOT = 2*AREA*TAPER/(TAPER+1)/SEMISPAN
CHORD_TIP = CHORD_ROOT/TAPER;
MAIN_NODES_Y = [0 0; SEMISPAN SEMISPAN]
%% Wing discretization
%
NX = 13;
NY = 3;
XP_NODES = ones(NY,NX);
YP_NODES = ones(NY,NX);
ZP_NODES = ones(NY,NX);
DELTA_LX = CHORD_ROOT/NX;
DELTA_LY = SEMISPAN/NY;
XP_NODES(1,:) = linspace(0,CHORD_ROOT,NX).*XP_AIRFOIL';
ZP_NODES(1,:) = CHORD_ROOT*XZ(:,2)';
%ZP_NODES(1,:) = linspace(0,CHORD_ROOT,NX).*ZP_AIRFOIL';
%XP_NODES(1,:) = XP_NODES(1,:).*XP_AIRFOIL'
%XP_NODES = linspace(0,CHORD_TIP)
ZP_NODES(end,:) = CHORD_TIP.*XZ(:,2)';
MESH = [XP_NODES' YP_NODES' ZP_NODES']
%%
%}
end

Rik on 15 Aug 2019
If you want to linearize an array, you can use (:):
[XP_NODES,YP_NODES,ZP_NODES]=deal(XP_NODES',YP_NODES',ZP_NODES');
MESH = [XP_NODES(:) YP_NODES(:) ZP_NODES(:)];
##### 2 CommentsShowHide 1 older comment
Rik on 15 Aug 2019
Because Matlab is column based. The fprintf function goes through your matrix column by column, not row by row. It is an error that is easy to make (it even ended up in my master thesis).
The solution is to either transpose the matrix when you input it to fprintf, or to use the separate arrays (which you then shouldn't need to linearize).
fprintf(fileID,' %12.10f %12.10f %12.10f \r\n',XP_NODES,YP_NODES,ZP_NODES);