Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Matlab coding

Status
Not open for further replies.

thesiswork

Student
Joined
Feb 8, 2022
Messages
11
Location
SE
Hello,

I want to create a txt file from matlab. Here's the txt file I want to create and attaching the matlab code as well. You can use any dummy matrix instead of values1
Screenshot_2022-03-05_141400_ftesoc.png


% random numbers for data to write to text file:
str(1) = "TABLED1";
data1 = [str(1) 2001];
% data2 = values;

A = values((1:4),(1:3));

% open the file for writing:
fid = fopen('test_output.txt','w');

% write each value as an 8-character-wide floating-point number, followed by
% a space; after every 10 such columns of values, write a newline (\n):
fprintf(fid,'%s %g\n',data1);
fprintf(fid,'%s',"+");

for i = 1:4
for j = 1:3

fprintf(fid,[repmat('%8.3f',i,10) ' \n'],A.');
% if repmat(A(1,>9)) %If the data exist from 9th column than it should have '+' sign in 10th column
% fprintf(fid,'%s',"+");
% end
end
end


% close the file:
fclose(fid);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top