How do I prelallocate this sed as there is no loop here?
1 view (last 30 days)
Show older comments
Nitesh Kumar Singh
on 6 Sep 2021
Commented: Nitesh Kumar Singh
on 6 Sep 2021
i have used uLS1 = zeros(1:N_ele); , uLS2 = zeros(1:N_ele);, uLS3 = zeros(1:N_ele); to remove prealloacting error (is this correct) but same error still come in this line sed(:,a) = (uLS1' + uLS2' + uLS3')/3; How do I prelallocate this sed as there is no loop here?
Getting this error in command window "Unable to perform assignment because the indices on the left side are not compatible with the size of the right side." Error in main_file (line 90) sed(:,a) = (uLS1' + uLS2' + uLS3')/3;
uLS1 = zeros(1:N_ele);
uLS2 = zeros(1:N_ele);
uLS3 = zeros(1:N_ele);
for p = 1:N_ele
uLS1(p) = 1/2*(sigma_1(p,2:7)*epsilon_1(p,2:7)');
uLS2(p) = 1/2*(sigma_2(p,2:7)*epsilon_2(p,2:7)');
uLS3(p) = 1/2*(sigma_3(p,2:7)*epsilon_3(p,2:7)');
end
% AVERAGE OF ALL LOADCASES
sed(:,a) = (uLS1' + uLS2' + uLS3')/3;
0 Comments
Accepted Answer
KSSV
on 6 Sep 2021
When you use the way you have shown,MATLAB created a n-D zeros matrix. You need to use as shown below:
uLS1 = zeros(1,N_ele);
uLS2 = zeros(1,N_ele);
uLS3 = zeros(1,N_ele);
for p = 1:N_ele
uLS1(p) = 1/2*(sigma_1(p,2:7)*epsilon_1(p,2:7)');
uLS2(p) = 1/2*(sigma_2(p,2:7)*epsilon_2(p,2:7)');
uLS3(p) = 1/2*(sigma_3(p,2:7)*epsilon_3(p,2:7)');
end
% AVERAGE OF ALL LOADCASES
sed(:,a) = (uLS1' + uLS2' + uLS3')/3;
More Answers (0)
See Also
Categories
Find more on Numeric Types 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!