In this Matlab program you will be working with two arrays which are inputted fr
ID: 3839810 • Letter: I
Question
In this Matlab program you will be working with two arrays which are inputted from one or two files. Here are the task you need to complete: Read the X and Y values from a data file (or two separate data files) Add the X and Y arrays, also called vectors, to get a third array Z. Divide the X by Y and get the resulting array V (note that the division is done element by element otherwise this will make no sense. Multiply the X and Y arrays and store the result in the array W. Print the result into an output file called myoutput.txt.Explanation / Answer
fid=fopen('myoutput.txt','w'); %For creating output file
M = dlmread('myinput.txt') %Reading input file
X = M(:,1); %Reading first column data into X
Y = M(:,2); %Reading Second column data into Y
Z=X+Y; %Adding elements in X , Y
V=X./Y; %Dividing elements in X , Y
W=X.*Y; %Multiplying elements in X , Y
%% Printing the results to output file
fprintf(fid,'%d ',Z);
fprintf(fid,' ');
fprintf(fid,'%d ',V);
fprintf(fid,' ');
fprintf(fid,'%d ',W);