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!