MATLAB Tutorial Lesson #07: File I O Basics

preview_player
Показать описание
Description
Рекомендации по теме
Комментарии
Автор

Thank you , Professor Rhudy, I will keeping following your tutorial,
very appreciated for what you did for matlab learner like me,

thumb up, up , up

ronniewang
Автор

Thanks for the work. Please enlarge the writings that we can see it clearly

EcheEmmanuelSylvester
Автор

thank you a lot you cant imagine how much you helped me ❤️

blackcat-dzsp
Автор

Thank you very much. You are the best.

biswabhanupuhan
Автор

%% calculate the force array example
% vector of mass
m = 0.1 : 0.1 : 5 ; % kg
% vector of accelerations
a = 0.1 : 0.1 : 1 ; % m/s^2

% create for loop
f = zeros(length(m), length(a)) ; % put f rather than f (i, j),
for i = 1: length (m)
for j = 1 : length (a)
f(i, j) = m (i) * a (j);
end
end
disp (f)
disp (f(i, j)) % why shows the last number in the matrix

Hi, Prof Rhudy,
abover it the code learning from you tutorial

I have question,
disp (f(i, j)) % why shows the last number in the matrix ?? not the first number

ronniewang
Автор

Hi, Professor Rhudy

I have a problem when learning your tutorial, please see code below

%% calculate the force array example
% vector of mass
m = 0.1 : 0.1 : 5 ; % kg
% vector of accelerations
a = 0 : 0.1 : 1 ; % m/s^2

% create for loop
f = zeros(length(m), length(a)) ; % put f rather than f (i, j),
for i = 1: length (m)
for j = 1 : length (a)
f(i, j) = m (i) * a (j);
end
end
disp (f) % why shows the last number in the matrix

%% create a text file from the forces

fid = fopen ('matlab_example.txt', 'wt' );
for i = 1 : length (m)
for j = i : length (a)
fprintf( fid, '%4.2f', f(i, j) ); % what if u put \n in this position, why ans is different
end
fprintf (fid, '\n')
end
fclose(fid);

%% read the data back in from the txt file
text_data = importdata ('matlab_example.txt');

%% import the data into xls file
xlswrite ('matlab_example.xls', text_data);

%%

when run it the command windows shows
:
Input data must be a numeric, cell, or logical array.

Error in matlab_example_txt (line 31)
xlswrite ('matlab_example.xls', text_data);

How could that possible, why such problem appears

Thanks in advance

ronniewang
Автор

fid = fopen ('matlab_example_txtfile.txt', 'wt' );
for i = 1 : length (m)
for j = i : length (a)
fprintf( fid, '%4.2f \n', f(i, j) ) % what if u put \n in this position, why ans is different
end
end

% what if u put \n in this position, why ans is different

sorry I am kinda new to matlab

ronniewang