OpenViBE forum http://openvibe.inria.fr/forum/ 

Help with Matlab scripting http://openvibe.inria.fr/forum/viewtopic.php?f=17&t=9974 
Page 1 of 1 
Author:  Yael [ Sun Sep 02, 2018 12:01 pm ]  
Post subject:  Help with Matlab scripting  
Hi, I've seriously tried everything, yet I can't figure out what is the problem. The matlab tutorials works fine, that means that there is no problem with the matlab engine calling, yet when I try to write a basic scenario the whole system crash. Please help. here are the matlab code (since I can't attach them as files): Code: function box_out = OV_EFP1_Initialize(box_in) disp('Matlab initialize function has been called.') box_out = box_in; end function box_out = OV_EFP1_Process(box_in) for i = 1: OV_getNbPendingInputChunk(box_in,1) [box_in, start_time, end_time, matrix_data] = OV_popInputBuffer(box_in,1); box_in = OV_addOutputBuffer(box_in,1,start_time,end_time,matrix_data); end % Pass the modified box as output to continue processing box_out = box_in; end function box_out = OV_EFP1_Uninitialize(box_in) disp('Matlab uninitialize function has been called.') box_out = box_in; end Many thanks, Yael

Author:  Yael [ Tue Sep 04, 2018 8:46 am ] 
Post subject:  Re: Help with Matlab scripting 
Hi, So when I attach my code onto tutorial 2 code it works, but when I delete the parts of the tutorial that I don't need the system crash again. meaning the openvibe designer shutdown. please what am I doing wrong? Many thanks, Yael 
Author:  jtlindgren [ Wed Sep 05, 2018 2:53 pm ] 
Post subject:  Re: Help with Matlab scripting 
Hello Yael, Designer shouldn't crash  if it does, thats a bug. I'll take a look. I first thought it could be the changed function names, but then these can be specified in the box config... Cheers, Jussi 
Author:  jtlindgren [ Wed Sep 05, 2018 3:41 pm ] 
Post subject:  Re: Help with Matlab scripting 
Ok, getting back on this, the problem is that your code is missing the assignment of the header  in OV all streams must have one. You need to add the following to the part of Process() where you iterate over the inputs, Code: box_in.outputs{1}.header = box_in.inputs{1}.header; The crash on the other hand was a C++ bug in the Matlab box, I'll fix that in git. Thanks for the report! Best, Jussi 
Author:  Yael [ Wed Oct 03, 2018 10:19 am ] 
Post subject:  Re: Help with Matlab scripting 
Thanks Jussi, sorry on the delay, we had many holidays and vacation time I managed to fix the problem by deleting this line from the code: box_in = OV_addOutputBuffer(box_in,1,start_time,end_time,matrix_data); I don't know why but it works perfectly without it. The only problem I have now is when assigning new variables to the user data in the box in I can't always call them, I have no idea why it sometimes works and in others doesn't. for example: when using variable as counter it works : box initialize function: box_in.user_data.nb_matrix_processed =0; box process function: box_in.user_data.nb_matrix_processed = box_in.user_data.nb_matrix_processed + 1; if (box_in.user_data.nb_matrix_processed>=4) && mod((box_in.user_data.nb_matrix_processed1),3)==0 yet when using it to call a file name such: box initialize function: selpath =uigetdir; box_in.user_data.path=selpath; filename3=sprintf('%s',box_in.user_data.path,'\eegdata.mat'); box_in.user_data.filenamedata=filename3; box uninitialized function: d=importdata(box_in.user_data.filenamedata); if box_in.user_data.count*1536<size(d,1) k=box_in.user_data.count+1; k1=num2str(k) filename1=sprintf('%s',box_in.user_data.path,'\eegdata') filename2=sprintf('%s',k1,'.mat') filename=sprintf('%s%s',filename1,filename2) save(filename,'c') it doesn't work when simply using: save(box_in.user_data.filenamedata,'c'). another example that isn't working is for: box initialize function: box_in.user_data.g_electrode=0; box process function: if(box_in.user_data.g_electrode==0) it gives an error for this line. is there any logic when using this user data variables? when can I call them and how (is it different than what I've tried so far). Many thanks, Yael 
Author:  jtlindgren [ Wed Oct 03, 2018 12:18 pm ] 
Post subject:  Re: Help with Matlab scripting 
Hi, the following work just fine for me. Can you try these and if they work, modify them to produce your error? Code: function box_out = Initialize(box_in) disp('Matlab initialize function has been called.') box_in.user_data.bool = false; box_in.user_data.number = 777; box_in.user_data.string = 'teststring'; box_in.user_data.counter = 0; % Don't forget to pass the modified box as output. box_out = box_in; end function box_out = Process(box_in) disp('Matlab process function has been called.') % disp(box_in.user_data) txt = sprintf('Bool %d\n', box_in.user_data.bool); disp(txt); txt = sprintf('Int %d\n', box_in.user_data.number); disp(txt); txt = sprintf('String %s\n', box_in.user_data.string); disp(txt); txt = sprintf('Counter %d\n', box_in.user_data.counter); disp(txt); box_in.user_data.counter = box_in.user_data.counter + 1; % Pass the modified box as output to continue processing box_out = box_in; end function box_out = Uninitialize(box_in) disp('Matlab uninitialize function has been called.') disp(box_in.user_data); box_out = box_in; end ps. I'm not sure your modification is appropriate that you mention in the beginning. Please try this hotfix which should address the crash issue, viewtopic.php?f=13&t=9961&p=15889&hilit=matlab#p15889 Cheers, Jussi 
Author:  Yael [ Wed Oct 03, 2018 1:22 pm ] 
Post subject:  Re: Help with Matlab scripting 
Hi, thanks, now I know what is the problem I am calling another function from the process function. the function is located just bellow in the process function code. I thought that the user data variables are global, do you have any idea how can I call them without doing upload of the file? can I define the user data variables as global? Thanks, Yael 
Author:  Yael [ Thu Oct 04, 2018 6:34 am ] 
Post subject:  Re: Help with Matlab scripting 
Thanks for all your help, I've figured it out, stupid mistake. Thanks again, Yael 
Author:  jtlindgren [ Thu Oct 04, 2018 8:24 am ] 
Post subject:  Re: Help with Matlab scripting 
Ok, great. Btw I imagine global variables work just as they usually do in Matlab. And you can of course pass box_in further to some of your own functions. Cheers, Jussi 
Author:  Yael [ Thu Oct 04, 2018 12:40 pm ] 
Post subject:  Re: Help with Matlab scripting 
Thanks, I did transfer the box_in to the next function and retrieved it, this is how I solved the problem, as I said stupid mistake, that took me a whole day. Thanks again, Yael 
Page 1 of 1  All times are UTC 
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ 