How to send a value from matlab to mysql?

조회 수: 1 (최근 30일)
Martijn Roks
Martijn Roks 2019년 4월 12일
댓글: Martijn Roks 2019년 4월 13일
Hello,
I need to send the value handles.Data to my sql table, but I keep getting a error and don't know how to solve this problem. The value's that goes in to Data are coming from the arduino with a potmeter. And everything works except de sending part. So the function verstuur_calback and then the query=.... code doesn't work.
Could someone help me solve this? Maybe I need to put it in a for loop or something like that, but I don't know.
function inputdata_Callback(hObject, eventdata, handles)
% hObject handle to inputdata (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
board= arduino();
b=0;
for i= 1:1:10
analog= readVoltage (board, 'A0');
writePWMVoltage (board, 'D3', analog);
disp(['analog= ', num2str(analog)]);
pause(1);
A(i)= analog;
b= b+1;
B(i)= b;
end
A=A';
B=B';
handles.Data= [B A];
disp(handles.Data);
colnames= {'PK','Voltage'};
set(handles.uitable2,'data',handles.Data ,'ColumnName',colnames);
guidata(hObject, handles);
function verstuur_Callback(hObject, eventdata, handles)
% hObject handle to verstuur (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
gebruikersnaam= get(handles.edit_gebruikersnaam, 'String');
wachtwoord= get(handles.edit_wachtwoord, 'String');
datasource= get(handles.edit_tabel, 'String');
conn= database(datasource, gebruikersnaam, wachtwoord, handles.driver, handles.url);
query= ['INSERT INTO ' table ' VALUES (''''Data'''')'];
execute(conn,query);
close (conn);
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2019년 4월 12일
편집: Geoff Hayes 2019년 4월 12일
Martijn - what is the full error message? Is the error from
query= ['INSERT INTO ' table ' VALUES (''''Data'''')'];
(not sure where Data is defined...)
Maybe Guillaume's answer at https://www.mathworks.com/matlabcentral/answers/455843-putting-two-seperate-columns-in-to-one-variable-and-how-to-insert-a-array-into-mysql will help. If this question is in response to his answer, then please further the conversation there rather than creating a new question.
Martijn Roks
Martijn Roks 2019년 4월 13일
This is my full error, I think Data needs to be handles.Data. Because that is where I saved the values from the potmeter (voltage) in de function before.
% Error using Week7>verstuur_Callback (line 158)
%All input arguments must be tables.
%Error in gui_mainfcn (line 95)
% feval(varargin{:})
%Error in Week7 (line 42)
% gui_mainfcn(gui_State, varargin{:});
%Error in
%matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Week7('verstuur_Callback',hObject,eventdata,guidata(hObject))
%Error while evaluating UIControl Callback.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by