Borrar filtros
Borrar filtros

Export a matrix to a txt file

5 visualizaciones (últimos 30 días)
Kasper
Kasper el 12 de Jun. de 2015
Comentada: Kasper el 15 de Jun. de 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.

Respuesta aceptada

Anthony Poulin
Anthony Poulin el 12 de Jun. de 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.
  1 comentario
Kasper
Kasper el 15 de Jun. de 2015
I'm not quite sure how to implement the algorithm Azzi's has posted into your code?

Iniciar sesión para comentar.

Más respuestas (2)

Azzi Abdelmalek
Azzi Abdelmalek el 12 de Jun. de 2015
for k=1:size(N,1)
str{k,1}=[ '''' char(N(k,1)) ' ' char(N(k,2)) ' ' char(N(k,3)) '''' ]
end

Kasper
Kasper el 15 de Jun. de 2015
Thanks to both of you! I'd wish I could give credit to both of you for answering my question.

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by