Info

This question is closed. Reopen it to edit or answer.

Hi can somebody help me by my for-loop.. there is a mistake but i dont know how to solve it .. i give you just the part where the error comes: Attempted to access mu(5); index out of bounds because numel(mu)=4. Error in veranderung (line 76) s

1 view (last 30 days)
d=[0 0.0125 0.1 0.16];
lambda=[0.00001 0.25 0.04 2.3];
mu=[0 8 1 130];
...
a=d./lambda;
R_theta=[R_Si,a,R_Se]; % Festlegung der Datenmenge R_theta
for i=length(R_theta); % Anzahl der Menge zählen
theta=T_i; % Innentemp. als Startwert festlegen
% preallocate various vectors
T_iErg=zeros(1,length(i));
SdErg=zeros(1,length(i));
PsErg=zeros(1,length(i));
for n=1:i % Laufparamter mit Anzahl der Datenmenge festlegen
theta=T_i-(R_theta(n).*U_Wert.*Delta_T); % Funktion Temp. Theta
T_i=theta; % Parameter aktualisieren
disp('°C') % Anzeige des Ergebnisnamen
disp(T_i)
T_iErg(n)=T_i;
plot(T_iErg, 'b*') % Anzeige der berechneten Temperatur
hold on;
sd=mu(n+1)*d(n); % Berechnen der sd-Werte
SdErg(n)=sd; % Alle Sd-Werte speichern in dem Ergebnisvektor SdErg
plot(SdErg, 'r*') % Plot Befehl, alles in einen Diagramm zeichnen
hold on;
if theta>0 % Berechneung der Drücke für Temp. >0
P_S=288.68.*(1.098+theta./100).^8.02; % Funktion für Druck
disp('Pa') % Anzeige Parametername
disp(P_S) % Anzeige Paramter-Wert
else
P_S=4.689.*(1.486+theta./100).^12.3; % sonst. Funktion
disp('Pa') % Anzeige
disp(P_S) % Anzeige
end
PsErg(n)=P_S; % Alle P_S -Werte speichern in dem Ergebnisvektor PsErg
%hold on;
%plot(SdErg,PsErg) % Plot
xlabel('sd [m]') % x-Achsenbeschriftung
ylabel('P_S [Pa]') % y-Achsenbeschriftung
end
end

Answers (1)

dpb
dpb on 14 May 2015
for i=length(R_theta); % Anzahl der Menge zählen
...
% preallocate various vectors
T_iErg=zeros(1,length(i));
NB: length(i) here == 1 so your "vectors" are simply 1x1. If the intent is they're to be same size as R_theta, then use
zeros(size(R_theta))
instead as RHS.
for n=1:i
...
sd=mu(n+1)*d(n);
Questions of style aside of using i as a variable other than the builtin complex sqrt(-1) or knowingly aliasing it for more than the index of a simple loop, we can't know the dimensionos of R_theta for certain as all we see is that it is built from three components earlier. If one (or more) of those is larger than a single value, then length(R_theta) would be >3 and that would explain the problem.
Given the error did occur, we must presume that must be the case (or, of course, the code posted isn't exactly what was actually run is also possible).

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!