My array returns all zeros. Help

2 visualizzazioni (ultimi 30 giorni)
Alex
Alex il 10 Dic 2014
Risposto: Aditya Nair il 2 Gen 2021
So my 'resultarray' in the 'deOxygen' function gives me all zeros and I'm not sure why. The values of the pollutiondata.txt file are as follows: array =
5.0000
1.0000
0.0000
20.0000
0.0550
0.2000
These are rounded and I don't want them to be.
Here is my entire code:
function myHW7()
% Alex
% December 12, 2014
% myHW7.m
load PollutionData.txt;
array = PollutionData(:,1); %#ok<NODEF>
timearray = (0:.5:250);
reshape(timearray, [501,1]);
array(3,:) = array(3,:) .* 0.001076; %conversion
array(6,:) = array(6,:) .* 0.0002778; %conversion
constant = reaeration(array);
resultarray = deOxygen(array , timearray, constant);
plot(timearray(:,1) , resultarray(:,1))
xlabel('Time after pollutant is added(hours)');
ylabel('Dissolved oxygen deficit (mg/l)');
for k1= 1:501
if resultarray(k1) == array(1,:)
disp(['The deficit will equal the initial deficit at time ' num2str(timearray(k1))])
end
end
return
function constant = reaeration(array)
constant = ((array(5,1) * array(3,1)) ^ 0.5) / (array(4,1) .^ 1.5);
return
function resultarray = deOxygen(array , timearray, constant)
resultarray = zeros(1,1000);
a = (0:0.5:250);
for k1 = 1:length(a)
resultarray(k1) = (((array(6,1) .* array(2,1)) ./ (constant - array(6,1))) .* (exp(-array(6,1) .* timearray(k1) .* 3600) - exp(-constant .* timearray(k1) .* 3600))) + (array(1,1) .* exp(-constant .* timearray(k1) .* 3600));
end
reshape(resultarray, [1000,1]);
return
Any ideas?
Thanks
  3 Commenti
Alex
Alex il 10 Dic 2014
what exactly should i split up? the equation of the result array you mean?
Alex
Alex il 10 Dic 2014
so i get the correct values for the array when i go through the for loop, but as soon as i go to the next point, it goes to zero. Is it possible that something is wrong with the passing the array back to the main function?

Accedi per commentare.

Risposte (1)

Aditya Nair
Aditya Nair il 2 Gen 2021
Hey! I recently encountered a similar problem. After racking my brains I realised that referencing an array incorrectly could actually make a new array whose values are set to zero. I was referencing the 1-D arrays in my 2-D array x(91,1500) as x(i) as opposed to x( i, : ) which is actually the proper way. Hope this 6 year late comment helps!

Community Treasure Hunt

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

Start Hunting!

Translated by