Reputation: 75
I want to create a text file like this with Matlab but i don't know how should I do that.
range(0,25e-9,0+600e-9),range(0+600e-9,1e-4,1.000000e-03),range(1.000000e-03,25e-9,1.000000e-03+600e-9),range(1.000000e-03+600e-9,1e-4,2.000000e-03),range(2.000000e-03,25e-9,2.000000e-03+600e-9),range(2.000000e-03+600e-9,1e-4,3.000000e-03)
for example here I want to create 6 point and I can do it by myself. But if I want create 100 point or 500 point I have to use Matlab. I wrote a code and create a matrix something like this but what I want is different. It's my code but I cant use it.....
clc
clear
close all
stp1=25e-9;
stp2=1e-4;
A=600e-9;
B=1e-3;
i=3;
F=zeros(i,3);
for i=1:i
if i==1
F(i,1)=0;
F(i,2)=stp1;
F(i,3)=A;
else
if mod(i,2)==0
F(i,1)=F(i-1,3);
F(i,2)=stp2;
F(i,3)=(i/2)*B;
else
F(i,1)=F(i-1,3);
F(i,2)=stp1;
F(i,3)=F(i,1)+A;
end
end
end
for example this is my matrix:
` 0.0000e+000 25.0000e-009 600.0000e-009
600.0000e-009 100.0000e-006 1.0000e-003
1.0000e-003 25.0000e-009 1.0006e-003`
I want to put them in one line and this like this:
`range(0.0000e+000,25.0000e-009,600.0000e-009),range(600.0000e-009,100.0000e-006,1.0000e-003),range(1.0000e-003,25.0000e-009,1.0006e-003)`
you know I want to add range(A(1,1),A(1,2),A(1,3)),range(A(2,1),A(2,2),A(2,3))
to my text file.... I hope I have explained well that I want.
Upvotes: 0
Views: 452
Reputation: 2854
I've put some code together below to help move this along. Please comment and I can adjust (or others can post answers based on updated information).
I'm still not sure exactly what outcome you're after.
For reference, you can see examples of file I/O documentation for dlmwrite
here and for fprintf
here. Notice you can specify the delimiter with dlmwrite
and the exact format with fprintf
.
A = [0.0000e+000 25.0000e-009 600.0000e-009;
600.0000e-009 100.0000e-006 1.0000e-003;
1.0000e-003 25.0000e-009 1.0006e-003];
dlmwrite('TestFile.txt',A) % Example use of dlmwrite
B = range(A,2); % Range of the rows of A
dlmwrite('TextFile2.txt',B)
C = cell(size(A,1),1);
fileID = fopen('TestFile3.txt','w+');
formatstr = '%12s\r\n';
for k = 1:size(A,1)
C{k}=['range(A(' num2str(k) ',:)'];
fprintf(fileID,formatstr,C{k});
end
fclose(fileID);
Hope this helps.
Upvotes: 1