(MATLAB beginner) How can I solve this error: In an assignment A(:) = B, the number of elements in A and B must be the same.
Show older comments
I'm trying to use MATLAB for my SWMM project in calibrating certain parameters. Shown below was the part of the program:
runvol_mea=[2.071
];
RunVol_mea=runvol_mea(1,:);
peakf=[0.122
];
PeakF_mea=peakf(1,:);
% Upper and Lower boundaries of parameters
lb = [250 60 0.9];
ub = [350 80 1.4];
% populate initial starting vertices (6 vertices) k = 2n ; n=3 (number of parameters to be calibrated)
par_1=zeros(6,3);
for i=1:6
par_o(i,:)=lb+rand(1,3).*(ub-lb);
end
% Model run
par=par_o;
max_int=300; % maximum number of iteration
Toler_=zeros(10,3); % Counter check
RunVol_sim=zeros(1,6); % number of vertices / number of storms
PeakF_sim=zeros(1,6);
E=zeros(1,1);
for i=1:6 % for 6 different vertices
%i
% Changing Subcatchment Area
Data{1,1}{index3+1}(52:58)=sprintf('%6.4f',par(i,1)); (This part was the error)
% Changing % impervious
Data{1,1}{index3+2}(59:61)=sprintf('%2f',par(i,2));
% Changing Subcatchment width range
Data{1,1}{index3+4}(62:67)=sprintf('%5.2f',30.72*par(i,3));
In the command window, it shows,
??? In an assignment A(:) = B, the number of elements in A and B
must be the same.
Error in ==> Tbftest at 60
Data{1,1}{index3+1}(52:58)=sprintf('%6.4f',par(i,1));** *
Its my first time using MATLAB and my seniors doesn't know how to handle this as well. I really appreciate anyone's help on this.
Accepted Answer
More Answers (1)
Walter Roberson
on 12 Feb 2014
1 vote
52:58 is seven locations, but your 6.4f format is producing six characters.
Categories
Find more on Get Started with MATLAB 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!