Search code examples
matlabuser-interfacefor-loopmatrixhandle

matlab gui handles for unknown matrix size


I am writing a GUI now which contains a button that load a matrix:

function Load_Profile_Callback(hObject, eventdata, handles)
% hObject    handle to Load_Profile (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

[FileName PathName] = uigetfile('*.mat','MATLAB Files');
handles.matrix=importdata([PathName FileName]);

next, i want to define each column of this matrix to be different channel for example:

handles.Ch01Gr01=handles.matrix.Data(:,2);
handles.Ch01Gr02=handles.matrix.Data(:,3);
handles.Ch01Gr03=handles.matrix.Data(:,4);
handles.Ch01Gr04=handles.matrix.Data(:,5);
handles.Ch01Gr05=handles.matrix.Data(:,6);
handles.Ch01Gr06=handles.matrix.Data(:,7);
handles.Ch01Gr07=handles.matrix.Data(:,8);

In case i dont know how many columns there are in this matrix, is there any option to solve this in for loop (or anyother idea will be good aswell )to run on this matrix dimension?


Solution

  • You can create a cell array for channel:

    numch = size(handles.matrix, 2);
    for i = 1:numch
        handles.Ch01Gr{i} = handles.matrix.Data(:, i);
    end