How do I prelallocate this sed as there is no loop here?

1 view (last 30 days)
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;

Accepted Answer

KSSV
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;
  1 Comment
Nitesh Kumar Singh
Nitesh Kumar Singh on 6 Sep 2021
sed(:,a) = (uLS1' + uLS2' + uLS3')/3;
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 0-by-1.
on moving cursor on sed shwoing consider preallocating for speed.
how to remove this error sir?
thank you sir

Sign in to comment.

More Answers (0)

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!