How to I change the time step in the following loop, so the new time is for the next line of code beign read?
2 ビュー (過去 30 日間)
古いコメントを表示
So I have this data that is a three column vector, which has 30 rows. The data is in the columns: volts, counts, time. The time column all says 500ms for all of the rows. But for the second row I would like the time to be adjusted to 1000ms, then by 1500ms and so on and so forth for all of the other lines of data. How do I do this for inside the loop? Also how do I plot this accordingly, I am using a GUI, through using guide.
%Variables
p = 1000;
g = 9.81;
vs = 5;
while fgetl(handles.fid)~= -1
line = fgetl(handles.fid);
new_line = sscanf(line, '%f V, %i counts, %i ms');
t = new_line(3)/1000;
% Q = flowrate (L/s)
% h = head(m)
% P = pressure
% p = density of water
P = ((new_line(1)/vs) - 0.04)/0.0018;
% Finding head
h = (P/1000)/(p*g);
Q = new_line(2)/((t/1000)*330);
% Finding hydraulic power
H =(Q*p*g*h)/1000;
%%%%%%%%%%%%%%%%%%%%%Plotting %%%%%%%%%%%%%%%%%%%%%%%%%
hold all
handles.plot = plot(handles.axes1, t, P, 'o-');
drawnow
handles.plot2 = plot(handles.axes2, Q, t, 'o-');
drawnow
handles.plot3 = plot(handles.axes3, h, Q, 'o-');
drawnow
handles.plot4 = plot(handles.axes4, H, Q, 'o-');
drawnow
handles.data.pressure = P;
handles.data.time = t;
handles.data.hpower = H;
handles.data.flowrate = Q;
handles.data.head = h;
%Update handles
guidata(hObject,handles);
end
%save changes to the handle
guidata(hObject,handles);
1 件のコメント
回答 (1 件)
Sammit Jain
2018 年 5 月 18 日
To handle this more intuitively, you can initialize a counter outside the loop (say k=0).
Inside your loop you can then make the following change to get the total time elapsed:
t = new_line(3)*k/1000;
This should initialize every iteration with t as the time elapsed till then.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!