Matlab Assignment Help Made Easy How To Use Transpose Operator In Matlab
function [data x y] = readonly(fname,nhead,ncols)
% open the file to be read
fin = fopen(fname,'r');
if fin < 0
error(['Could not open ',fname,' for input']);
end
for i=1:nhead, buffer = fgetl(fin); end
% read the numerical data
data = fscanf(fin,'%f'); % Load the numerical values into one long vector
nd = length(data); % total number of data points
nr = nd/ncols; % number of rows; check (next statement) to make sure
if nr ~= round(nd/ncols)
fprintf(1,'\ndata: nrow = %f\tncol = %d\n',nr,ncols);
fprintf(1,'number of data points = %d does not equal nrow*ncol\n',nd);
error('data is not rectangular')
end
data = reshape(data,ncols,nr)'; % notice the transpose operator
x = data(:,1);
y = data(:,2:ncols);
MATLAB Assignment Help | MATLAB Programming Help | Assignment Help | Online Tutoring