My array returns all zeros. Help

조회 수: 7 (최근 30일)
Alex
Alex 2014년 12월 10일
답변: Aditya Nair 2021년 1월 2일
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
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일
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!

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by