How to arrange coordinates into 3 columns?

1 visualizzazione (ultimi 30 giorni)
Oscar Espinosa
Oscar Espinosa il 15 Ago 2019
Commentato: Rik il 15 Ago 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
150519 Orden de columnas.png
function WINGEODISC
%% Read airfoil
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_X = [0 CHORD_ROOT; tan(degtorad(LE_SWEPT)) CHORD_TIP+tan(degtorad(LE_SWEPT))]
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(end,:) = linspace(0,CHORD_TIP,NX)+tan(degtorad(LE_SWEPT)).*XP_AIRFOIL';
%XP_NODES = linspace(0,CHORD_TIP)
ZP_NODES(end,:) = CHORD_TIP.*XZ(:,2)';
MESH = [XP_NODES' YP_NODES' ZP_NODES']
%%
%}
end

Risposta accettata

Rik
Rik il 15 Ago 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 Commenti
Oscar Espinosa
Oscar Espinosa il 15 Ago 2019
Thank you Rik, now I'm trying to save that data to a file using the next code:
MESH = [XP_NODES(:) YP_NODES(:) ZP_NODES(:)];
fileID = fopen('mesh.txt','w');
fprintf(fileID,' %12.10f %12.10f %12.10f \r\n',MESH);
fclose(fileID);
but what I'm getting its the next .txt file:
0.0000000000 1.0000000000 0.0000000000
0.0041666719 1.0000000000 0.0977671942
0.0166666875 1.0000000000 0.1955343885
0.0500000625 1.0000000000 0.3077353394
0.1333335000 1.0000000000 0.4488038038
0.2500003125 1.0000000000 0.5898722683
0.4000005000 1.0000000000 0.7309407327
0.5833340625 1.0000000000 0.8720091971
0.8000010000 1.0000000000 1.0130776615
1.0500013125 1.0000000000 1.1541461259
1.3333350000 1.0000000000 1.2952145904
1.6500020625 1.0000000000 1.4362830548
2.0000025000 1.0000000000 1.5773515192
0.0000000000 1.0000000000 0.0000000000
0.3432760191 1.0000000000 0.1716380095
0.4832092660 1.0000000000 0.2416046330
0.6783945480 1.0000000000 0.3391972740
0.8975798620 1.0000000000 0.4487899310
0.9895484809 1.0000000000 0.4947742405
0.9808319340 1.0000000000 0.4904159670
0.9082334193 1.0000000000 0.4541167096
0.7717489967 1.0000000000 0.3858744983
0.5940086165 1.0000000000 0.2970043083
0.3992760891 1.0000000000 0.1996380445
0.2067246684 1.0000000000 0.1033623342
0.0000000000 1.0000000000 0.0000000000
0.0000000000 0.0000000000 0.0000000000
0.0000000000 0.0000000000 0.0000000000
0.0000000000 0.0000000000 0.0000000000
0.0000000000 0.0000000000 0.0000000000
0.0000000000 0.0000000000 0.0000000000
0.0000000000 0.0000000000 0.0000000000
0.0000000000 0.0000000000 0.0000000000
0.0000000000 0.0000000000 0.0000000000
0.0000000000 0.0000000000 0.0000000000
0.0000000000 0.0000000000 0.0000000000
0.0000000000 0.0000000000 0.0000000000
0.0000000000 0.0000000000 0.0000000000
0.0000000000 0.0000000000 0.0000000000
why they didn't keep the order?
Rik
Rik il 15 Ago 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);

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Airfoil tools 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