How to pre-allocate memory for 3d matrix?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
So I have a .m file which gives me 128x14 every millisecond, I am calling it and creating an object of it "h". so now i get this warning when i hove over class1, class11, class2, class22, class3, class33, class4 and class44 its asking me to preallocate memory for them, so I tried searching for the option and got this. And this is a GUI application.
class1(:,:,samples_output) = zeros(128, 14, size(x));
I place the above code under "y" but when i run it i get this error
Subscripted assignment dimension mismatch.
Error in training>start_training_Callback (line
97)
class1(:,:,samples_output) = zeros(128, 14,
size(x));
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in training (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)training('start_training_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
This is the code
x = [0;1;0;-1];
y = [1;0;-1;0];
h = EmotivEEG;
h.Run;
for k = 1:samples_output
location={};
s=cell(1,4);
for a = 1:4
location{1} = sprintf('UP');
location{2} = sprintf('RIGHT');
location{3} = sprintf('DOWN');
location{4} = sprintf('LEFT');
n = location{a};
s(a)=strread(sprintf(n),'%s','delimiter','');
end
set(handles.viewer_training,'YTick',[]);
set(handles.viewer_training,'XTick',[]);
scatter(x,y,'filled')
text((x-.1),(y+.2),s,'color',[1,0,0]);
hold on;
for s=1:size(x)
samples_class_text = sprintf('Samples: %s \n Class: %s',num2str(k), num2str(s));
set(handles.current_pos,'String',samples_class_text, 'FontSize', 15);
set(handles.viewer_training,'YTick',[]);
set(handles.viewer_training,'XTick',[]);
scatter(x(s),y(s),400,'MarkerFaceColor',[0 0 0]);
drawnow;
if s == 1
class1(:,:,s) = h.data;
class11(:,:,s) = h.data;
con1 = cat(3, class1(:,:,s), class11(:,:,s));
assignin('base','class1',con1);
elseif s == 2
class2(:,:,s) = h.data;
class22(:,:,s) = h.data;
con2 = cat(3, class2(:,:,s), class22(:,:,s));
assignin('base','class2',con2)
elseif s == 3
class3(:,:,s) = h.data;
class33(:,:,s) = h.data;
con3 = cat(3, class3(:,:,s), class33(:,:,s));
assignin('base','class3',con3)
elseif s == 4
class4(:,:,s) = h.data;
class44(:,:,s) = h.data;
con4 = cat(3, class4(:,:,s), class44(:,:,s));
assignin('base','class4',con4)
end
pause(1);
end
cla;
end
h.delete;
can anyone tell me how to preallocate the memory for those classes?
thanks in advance.
0 comentarios
Respuestas (1)
Image Analyst
el 7 de Feb. de 2015
h.data MUST be a 2D array - like a solid array, like an image or something. Is it? It can't be a row or column vector. It must be a 128 row by 14 column 2-D matrix or else it won't work. What does this say if you put it right after you get h but before it errors out:
whos h.data
size(h.data)
h.data
0 comentarios
Ver también
Categorías
Más información sobre Graphics Object Properties en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!