Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS 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
Feb 8, 2022
11
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);
 
Replies continue below

Recommended for you

Status
Not open for further replies.

Part and Inventory Search

Sponsor