Functional network coding in matlab

Hi everyone,
I have a cell array named B, I want to use all of the cells of it (inside of each cell I have a double matrix, for instance, the first cell is 30800*4 which is the timepoints of 4 channels) so I call it by " sig=B(:,:); " and " sig=B(:,:,:); " but I’ve got an error. I will attach the screenshot. Please let me know my mistake.

I really appreciate any help you can provide.

Neda

Hello,

It would help if you add the code that led to the error and the full error message. In the screenshot you attached, the error is that B is not loaded.

You might run into trouble trying to make a 3D matrix out of the elements of B because they appear to be different sizes.

Best,
Steven

Thanks for the answer.

I just wanted to gather all subjects and all channels together and filter the alpha band.

Hi,

From this screenshot it is not clear what shape B is, what the items in B represent, or what the error message is.

Also, in your code it looks like your will be overwriting subs_a1.

It might be easier if you instead copy/paste the code with the code format string (like this), surrounded by the “`” sign (you can also highlight your text and press the button that looks like this </> to do that formatting).

Best,
Steven

(%% Gathering all subjects in cd=1 EC1 Active
% Load EC1, Active
load B
sig= B(:,:);
cd=1; % cd1= EC1 Active
subs_al= zeros(size(sig));
% Design Filter for alpha
% bandpass butterworth filter
fl= 8;
fh= 12;
order= 3;
wn= [fl fh]/(fs/2);
type= ‘bandpass’;
[b,a]= butter(order,wn,type);
% Apply designed filter
subs_al= filtfilt(b,a,sig):wink:

Also, I think this code is not valid enough to understand the whole code. Needless to mention, you sent me the link (Complex Systems Group at URJC) to do step by step. I exactly want to do these steps but I really got baffled. Would you please guide me or link me with some one who can guide me in details.

Thanks in advance for your help.

Neda

What is the error you are getting when you are running the code?

Also, when you are preparing the filtfilt command, make sure your third argument is prepared in the following format:

Best,
Steven

the error is like this

You do not have a variable defined as B, so matlab cannot perform any operations on B. How are you trying to to define B?

I did not define it in my codes, but I have B in the path as a 3D matrix (.mat file) that includes information about each subject in every cell (It is a double matrix).

have you tried B=load('B.mat') ?

B=load(‘B.mat’)
This worked <3

but it still erroring in (filtfilt), I did not get what you meant in this reply.

The third input to filtfilt, which you named sig, must be an array or matrix, where each timeseries you want to filter is represented as a column (unless you decide to only filter one signal at a time, in which case in can be a single row vector).

1 Like

I tried but it did not solve. :frowning: I’ve really got confused

Can you please share the code that you tried and the error message you’ve received?


% convert struct to double matrix
B = struct2cell(sig);
out = cat(2,B{:});
% B= cell2mat(struct2cell(sig));

In the variable explorer (lower left corner of second screenshot), it is not clear what kind of variable sig is; knowing that would help. Also what is the shape of the item inside of B?

You have sig = B(:,:). I imagine that would just set sig equal to B. B looks to be a struct, which is not an accepted format for filtfilt. Is your input signal contained within B?

sig is a struct that has 1 field (1*14 cells).

What are in the cells?

each of cells is time series of one subject

It looks like that these timeseries should be the third input to filtfilt.