My array returns all zeros. Help

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 件のコメント

Adam
Adam 2014 年 12 月 10 日
Have you tried splitting up the code in deOxygen onto multiple lines and putting a breakpoint in to see what is going on in the function?
Also please use the '{} Code' button for formatting code to make it readable (select all your text that is code and just click it)
Alex
Alex 2014 年 12 月 10 日
what exactly should i split up? the equation of the result array you mean?
Alex
Alex 2014 年 12 月 10 日
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?

サインインしてコメントする。

回答 (1 件)

Aditya Nair
Aditya Nair 2021 年 1 月 2 日

0 投票

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!

カテゴリ

質問済み:

2014 年 12 月 10 日

回答済み:

2021 年 1 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by