Unable to run the code.
조회 수: 1 (최근 30일)
이전 댓글 표시
Unable to run the code. Plz if some one can guide
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% clc, clear all, close all, format long;
% This code was written to:
set(handles.pushbutton3, 'userdata', 0);
% 1) Acquire data from an already written excel sheet
% 2) Acquire data at every 30 seconds
% 3) Plot the acquired data at every 30 seconds also.
% Figure 1 is for plotting the first column of sensor data. It will be
% updated every once in 30 secs.
%figure(1)
axes(handles.axes4);
LiveLoad1 = plot(NaN,NaN,'linewidth',1.5,'color','r'); % Amplitude Plot.
grid on
xlabel('Stroke Length (in)','fontweight','bold')
ylabel('Polished Rod Load (lbs)','fontweight','bold')
title('Polished Rod Load Stream')
ax = gca;
ax.YAxis.Exponent = 0;
axes(handles.axes6);
LiveLoad2 = plot(NaN,NaN,'linewidth',1.5,'color','k'); % Amplitude Plot.
grid on
xlabel('Stroke Length (in)','fontweight','bold')
ylabel('Pump Load (lbs)','fontweight','bold')
title('Pump Load Data Stream')
ax = gcb;
ax.YAxis.Exponent = 0;
% Keep the time on your own. Threshold in your case will be 30. Because you want to update at every 30 sec. Just change
% it. I made it 3 so that I can see if there are any problems with running
% of the code.
Threshold = 60; ReadCount = 1;
% The code needs to now the time. This 'time' is slightly different than
% the time in your excel sheet in terms of 0 reference.
Time = 0
%StopTime = 5; % I make this 5 for diagnosis. In your case write how much you need. For instance if you need 500 seconds of data, enter that
% Necessary parameters.
index = 1; % This indec just updates our time reference and is not related to the time data coming from your DAQ.
tic % This is the start of our time.
while 1
java.lang.Thread.sleep(500)
Time(index) = toc;
if Time(end) > Threshold % If we have waited enough, we will read the data below.
ReadCount = ReadCount +1; % You take the first data at 30 secs. The next one will be after 60, 90, 120...
Threshold = Threshold*ReadCount; % Each time, postpone the read time for 30 secs with this. Remember, threshold in your case will be 30.
T = xlsread('1_Sheet.xlsx', 'Master Data B138', 'C:C'); % Read time from your excel sheet
U0 = xlsread('1_Sheet.xlsx', 'Master Data B138', 'D:D'); % Read position from your excel sheet.
Fpr = xlsread('1_Sheet.xlsx', 'Master Data B138', 'F:F'); % Read load data from your excel sheet.
% Load1 = xlsread('1_Sheet.xlsx', 'Master Data B138', 'F:F'); % Read load data from your excel sheet.
% Load2 = xlsread('1_Sheet.xlsx', 'Master Data B138', 'F:F'); % Read load data from your excel sheet.
% Remark: Please make sure that the excel file is in the relevant
% directory and you entered the file name with complete accuracy.
set(LiveLoad1,'XData',U0,'Ydata',Fpr); % Load 1 data Update on the figure --- > Live.
%% Get the other equations.
gc = 32.2;
c = 0.1;
rho = 490;
Aplus = 0.78; Aminus = 0.78;
E = 30.5*1e6;
Vs = sqrt((144*gc*E)/rho);
length = 2750 ;
Brackets_plus= (rho*Aplus)/(144*gc);
Brackets_minus= (rho*Aminus)/(144*gc);
delta_t = mean(diff(T));
delta_x =0.8*(Vs*delta_t);
pieces = (length) / (delta_x);
alpha = ((delta_x)/(delta_t^2))* ((Brackets_plus+Brackets_minus)/2);
% Displacements from the sensor
UU{1} = U0;
% Calculations for the the pieces from 2 to n-1.
%c = 0.2;
% Displacement at the 1st piece.
for j = 1:length(UU{1})
UU{2}(j,1) = (Fpr(j)*delta_x)/(E*Aplus) + UU{1}(j);
end
% Displacement at the Second Piece.
for j = 2:(length(UU{2})-1)
UU{3}(j,1) = (alpha*(1 + c*delta_t)*UU{2}(j+1) - ((alpha*(2+c*delta_t)) - (E*Aplus)/delta_x - (E*Aminus/delta_x))*UU{2}(j)...
+ alpha*UU{2}(j-1) - (E*Aminus/delta_x)*UU{1}(j)) / ((E*Aplus)/delta_x);
end
UU{3}(1) = [];
for k = 3:(pieces)
for j = 2:(length(UU{k})-1)
UU{k+1}(j,1) = ((alpha*(1 + (c*delta_t))*UU{k}(1+j)) - (((alpha*(2+(c*delta_t))) - ((E*Aplus)/delta_x) - ((E*Aminus/delta_x)))*UU{k}(j))...
+ (alpha*UU{k}(j-1)) - ((E*Aminus/delta_x)*UU{k-1}(j+1))) / ((E*Aplus)/delta_x);
end
UU{k+1}(1) = [];
end
% For the displacement at the pump, we need the (m-1)th and (m-2)th
% displacements which are already calculated. The cell matrix UU{end} is
% the mth, UU{end-1} is the (m-1)th and UU{UU-2} is the (m-2)th
% displacement. With respect to this:
% Apply the displacement at the pump formula. (6) in the paper.
for j = 2:(length(UU{end}) -1)
U_pump(j,1) = (1+c*delta_t)*UU{end}(j+1) - c*delta_t*UU{end}(j) + UU{end}(j-1) - UU{end-1}(j);
end
U_pump(1) = [];
% % Apply the force at the pump formula. (7) in the paper.
for j = 1:length(U_pump)
F_pump(j,1) = ((E*Aplus)/(2*delta_x))*(3*U_pump(j) - 4*UU{end}(j+2) + UU{end-1}(j+3))-3000;
end
set(LiveLoad2,'XData',U_pump,'Ydata',F_pump); % Load 1 data Update on the figure --- > Live.
% set(LiveLoad2,'XData',T,'Ydata',Fpr); % Load 2 data Update on the figure --- > Live.
drawnow % Draws immediately.
% handles structure with handles and user data (see GUIDATA)
if get(handles.pushbutton3, 'userdata') % stop condition
break;
end
% Hints: get(hObject,'String') returns contents of edit1 as text
end
index = index +1; % Every iteration lasts 500ms. This can be further increased or decreased or but it just to understand when to take data.
end
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!