2 views (last 30 days)

Hello, I'm using a peak picking command "mspeaks" and after it process my data, it outputs it into a cell array with the following format (92x1 cell). Each row corresponding to a different sample.

76x2 double

74x2 double

72x2 double

30x2 double

43x2 double

32x2 double

26x2 double

65x2 double

etc...

In each individual cell, the first column is the x-axis point (m/z) and the second column is the corresponding y-value (intensity). I tried using the following loop, but the different number of rows/peaks detected causes an error.

% PP_ERMNBP = 'the cell array mentioned above'

%Extract the peak list values

for i=1:size(PP_ERMNBP,1)

PP_extract_mz(:,i)=PP_ERMNBP{i,1}(:,1)

PP_extract_Y(:,i)=PP_ERMNBP{i,1}(:,2)

end

%%Resulting Error

%%Unable to perform assignment because the size of the left side is 76-by-1 and the size of the right side is 74-by-1.

Using "cell2mat" directly converts all the data into a single two column matrix which isn't useful, and transposing the cell array before hand also causes the same error.

I would like to extract all the x-axis points into one array/matrix, and all the y-axis points into another becauses I want to do some other operations and eventually save the data to a single .csv table (which I already have the script for).

Thanks for your help!

madhan ravi
on 14 Aug 2019

xy = cat(1,cell_array{:});

x = xy(:,1)

y = xy(:,2)

madhan ravi
on 14 Aug 2019

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 1 Comment

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/476151-how-to-extract-data-to-a-matrix-from-cell-arrays-with-varying-cell-lengths#comment_735085

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/476151-how-to-extract-data-to-a-matrix-from-cell-arrays-with-varying-cell-lengths#comment_735085

Sign in to comment.