Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 0-by-0.
4 views (last 30 days)
Show older comments
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Dec_05_test is made visible.
function Dec_05_test_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Dec_05_test (see VARARGIN)
% Choose default command line output for Dec_05_test
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
set(handles.togglebutton1,'Enable','On');
set(handles.pushbutton2,'Enable','On');
cd C:\path\to\eidors;
run startup;
% UIWAIT makes Dec_05_test wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Dec_05_test_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1"start".
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Make model:
set(handles.togglebutton1,'Enable','On');
set(handles.pushbutton2,'Enable','On');
model = mk_common_model('d2c2',8);
stim = mk_stim_patterns(8,1,'{ad}','{ad}',{},1);
model.fwd_model.stimulation = stim;
global close_1;
close_1=1;
global freeze;
freeze=0;
global img;
img = 1;
%clear the momory:
if ~isempty(instrfind)
fclose(instrfind);
delete(instrfind);
end
%Connect arduino to MATLAB:
clear
Arduino=serial('COM3','BaudRate',115200);%need to change the baudrate;
fopen(Arduino);
writedata=uint16(500); %0x01F4
fwrite(Arduino,writedata,'uint16') %write datac
% %define the data file:
A = zeros(64,2);%homo data
B = zeros(64,1);%inhomo data
%read 64 lines of data of Homogeneous data:
% 1 means times: 1 colums of 64 vector;
%20, 64
for s=1:20
for i=1:64 %read 64 lines of data
A(i,s) = fscanf(Arduino,'%f');
end
end
%A(A==1023) = 0;
%A=nonzeros(A');
%A=reshape(A,40,5);
%A = A(:,11:15);
A = A*5/1024;
A = A(:,6:20);
hom = mean(A,2);
A = [];
save('homg_test.mat','hom')
disp('Homogeneous data DONE')
j=1;
k=1;
n=0;%the number of complete vector
while close_1==1 %%Loop Program forever
try %%Keep trying for vector Data from ardunio file
for i=1:64 %read 64 lines of data
B(i,1) = fscanf(Arduino,'%f');
%There is only one vector,to construct the image.
end
%B = nonzeros(B)
D(:,k) = B;
k=k+1;
inhom = B*5/1024;
C(:,j) =inhom;
j=j+1;
save('inhom_test.mat','inhom')
B = [];
global Image1;
Image1 = inv_solve(model,hom,inhom); % regularization
T = 0.25*max(abs(Image1.elem_data(:)));
Image1.elem_data = soft(Image1.elem_data,T);
Image1.calc_colours.npoints = 128;
Image1.calc_slices.filter = ones(3)/9;
pause(0.1);
if freeze == 0
%pause(0.2);
show_slices(Image1);
%pause(0.001);
n = n+1;
n
else
pause(0.001);
end%%Keep closing txt file as to avoid crash in program
%fclose('all');
pause(0.2);%%Buffer time for program to process each individual(256 data points) for image reconstruction
catch
pause(0.01)
end
save('inhom_data_whole','C');
save('inhom_data_raw','D');
end
Erros :
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 0-by-0.
Error in Dec_05_test>pushbutton1_Callback (line 133)
A(i,s) = fscanf(Arduino,'%f');
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Dec_05_test (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Dec_05_test('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
Explanation and solution would be suffice
11 Comments
Walter Roberson
on 16 Sep 2020
https://www.mathworks.com/help/matlab/ref/serial.fscanf.html#buiolzb-10
fscanf is not certain to return exactly one value. It reads until terminator and so can return multiple values or no values. In case of timeout it returns the values so far, which might be no values.
You should assign the result of the fscanf to a variable and test the size of the variable instead of just assigning into array.
Answers (0)
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!