Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
clc
clear
L_s=180;
L_m=710;
L_h=740;
L_e=3850;
L_o=4720;
Q_sh=67;
Q_mh=36;
Q_he=161;
Q_eo=182;
Q_oo=212;
M=linspace(0, 710*6, 6);
[N(1,:)]=ClConc(180, M(1), 740, 3850, 4720); %problematic line according to Matlab
[N(2,:)]=ClConc(180, M(1), 740, 3850, 4720);
[N(3,:)]=ClConc(180, M(1), 740, 3850, 4720);
[N(4,:)]=ClConc(180, M(1), 740, 3850, 4720);
[N(5,:)]=ClConc(180, M(1), 740, 3850, 4720);
hold on
plot(M, N(:,1))
plot(M, N(:,2))
plot(M, N(:,3))
plot(M, N(:,4))
plot(M, N(:,5))
xlabel('loads of chlorine')
ylabel('concentration of chloride(ppm)')
title('loads of chloride vs concentration of chloride(ppm)')
legend('s', 'm', 'h', 'e', 'o')
hold off
function [c]= ClConc(L_s, L_m, L_h, L_e, L_o)
L=[L_s; L_m; L_h; L_e; L_o];
Q=[67 0 0 0 0; 0 36 0 0 0; -67 -36 161 0 0; 0 0 -161 182 0; 0 0 0 -182 212];
c=(Q./L);
end
1 commentaire
Dyuman Joshi
le 2 Nov 2022
1 - The output from your function is a matrix (5x5). You can not assign a matrix to a row.
2 - M is 6x1 where as N(:,i) will be 5x1. There will be a mismatch in plotting.
M=linspace(0, 710*6, 6)
N=ClConc(180, M(1), 740, 3850, 4720)
function [c]= ClConc(L_s, L_m, L_h, L_e, L_o)
L=[L_s; L_m; L_h; L_e; L_o];
Q=[67 0 0 0 0; 0 36 0 0 0; -67 -36 161 0 0; 0 0 -161 182 0; 0 0 0 -182 212];
c=(Q./L);
end
Réponses (2)
Voss
le 2 Nov 2022
clc
clear
L_s=180;
L_m=710;
L_h=740;
L_e=3850;
L_o=4720;
Q_sh=67;
Q_mh=36;
Q_he=161;
Q_eo=182;
Q_oo=212;
M=linspace(0, 710*6, 6);
result = ClConc(180, M(1), 740, 3850, 4720)
function [c]= ClConc(L_s, L_m, L_h, L_e, L_o)
L=[L_s; L_m; L_h; L_e; L_o];
Q=[67 0 0 0 0; 0 36 0 0 0; -67 -36 161 0 0; 0 0 -161 182 0; 0 0 0 -182 212];
c=(Q./L);
end
The result returned from ClConc is a 5x5 matrix. You try to assign it into a 1-by-something vector. That cannot work, and MATLAB lets you know that via an error message.
0 commentaires
Cris LaPierre
le 2 Nov 2022
The result of your function ClConc is a 5x5 matrix. The error is because you are trying to assign it to a single row of N. You have to assign it to something of the same size (5x5) or reshape it so that it is a single row.
Should the output of ClConc be 5x5?
If so, you may need to do something like this
N(1,:)=reshape(ClConc(180, M(1), 740, 3850, 4720),1,[]);
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!