Anyone know what I am getting this error?
Show older comments
if true
% code
end
function [RMax, RMaxHalf]= Mathworks_HalfMaxtimesRational()
%Grabbing your folder,grabbing files of interest, assigning length of folder, formatting documents,
delimiter = ','; %The comma is used to separate matrix subscripts and arguments to functions.
startRow = 25; %specifying the first row you want data from
fmt=[repmat('%f',1,2) '%*[^\n]']; %The fmt variable is the format string that maps the content of the file to the data variables you want returned--above it is two string variables and then an idiom to skip the rest of each record (line).
pn = uigetdir(pwd,'matlabbatch'); % Getting directory/folder from memory
d=dir(fullfile(pn, '*.csv')); %getting specific files from directory/folder
L=length(d); % so now preallocate knowing length...
RMax=zeros(L,1);
RTime_Half=RMax;
% and loop over the files...
for i=1:L
fid=fopen(d(i).name,'r'); %opening file # i
dataArray=cell2mat(textscan(fid, fmt, 'Delimiter', delimiter, 'headerlines', startRow, 'collectoutput',1));
fid=fclose(fid); %closing the file
Time_Hrs = dataArray(:,1);
Res = dataArray(:,2);
RMax(i)= max(Res);
RMaxHalf(i)=RMax(i)/2;
tmp=abs(Res-RMaxHalf(i));
[~,idx] = min(tmp);
RTime_Half(i) = Time_Hrs(idx);
end
xlswrite('Time_Half_Max.xlsx', [RMax RTime_Half])
ERROR MESSAGE In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in Mathworks_HalfMaxtimesRationalathome (line 18) RMax(i)= max(Res);
Accepted Answer
More Answers (1)
James Tursa
on 10 May 2017
Use the debugger. First, type the following:
dbstop if error
Then run your code. When the error occurs, the program will pause with all variables intact. Examine the variables in question to see what the sizes are etc. Then backtrack in your code to figure out why the sizes are not as expected.
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!