Export a matrix to a txt file
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kasper
am 12 Jun. 2015
Kommentiert: Kasper
am 15 Jun. 2015
Hello
We are trying to export two matrices to a .txt file. Tried several things but it doesn't seem to like symbolics. The code is like this:
clear all
% end points
X = [0 1];
Y = [0 0];
% intermediate point (you have to choose your own)
Xi = mean(X);
Yi = mean(Y) + 1/250;
Xa = [X(1) Xi X(2)];
Ya = [Y(1) Yi Y(2)];
t = 1:numel(Xa);
ts = linspace(min(t),max(t),numel(Xa)*10); % has to be a fine grid
xx = spline(t,Xa,ts);
yy = spline(t,Ya,ts);
plot(xx,yy); hold on; % curve
plot(X,Y,'or') % end points
plot(Xi,Yi,'xr') % intermediate point
syms L K
XA=yy*L;
YA=xx*L;
KPNR=(1:numel(Xa)*10);
key(1:numel(Xa)*10)=K;
A=[key;KPNR;XA;YA];
B=transpose(A);
BLA(1:numel(Xa)*10)=L;
z1=(1:numel(Xa)*10);
z2=(2:numel(Xa)*10+1);
H=[BLA;z1;z2];
N=transpose(H);
What we want, is to generate some keypoints for ANSYS. For the convenience, we want to include K and L, since it is commands in ANSYS. What we want is MATLAB to export the A and N matrices to two seperate .txt files without the '[ ]' but with the ','. But can't seem to find a workaround for the symbolics. We're not that experienced with Matlab unfortunately.
0 Kommentare
Akzeptierte Antwort
Anthony Poulin
am 12 Jun. 2015
Hello,
I give you this short code:
fileId = fopen('MatrixA.txt', 'w'); %To create a file
txtA = char(A); %To convert the symbolic matric into char
% To do: make an algorithm to put the Matrix in the right format "formatedA = f(txtA)"
fprintf(fileId, '%s', formatedA);
fclose(fileId);
If you test the code with fprintf(fileId, '%s', txtA);, you will see that the Matrix is not written like you want. It just needs an algorithm to put the matrix in the rigth format. Tell me, if you need help to do it.
Weitere Antworten (2)
Azzi Abdelmalek
am 12 Jun. 2015
for k=1:size(N,1)
str{k,1}=[ '''' char(N(k,1)) ' ' char(N(k,2)) ' ' char(N(k,3)) '''' ]
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!