Clear Filters
Clear Filters

Retrieving Arrays Within Set of Matrices

16 views (last 30 days)
Samuel
Samuel on 4 Jul 2024 at 21:39
Edited: Voss on 4 Jul 2024 at 22:18
Hello,
I have several sets of data that I want to plot on one graph. The problem is that each data set is in its own matrix. For instance, I have a 36x4 matrix (let's call it M). In each of the cells in the 4th column is a 516x2 matrix, corresponding to x and y values. The x values are the same for each of the 516x2 matricies, so I just want to plot the y values against one set of x values. I try to make an additional matrix (let's call it N) to have the y values all side by side by using the following code
N=[M{:,4}(:,2)]
But then I get the following error
Intermediate brace '{}' indexing produced a comma-separated list with 36 values, but it must produce a single value when followed by subsequent indexing operations.
The end goal is to be able to use this after iterative peak fitting across multiple similar data sets, but I need to be able to efficiently visualize the resulting plots. I would be grateful for any help on this. Thank you!

Answers (1)

Voss
Voss on 4 Jul 2024 at 22:17
Edited: Voss on 4 Jul 2024 at 22:18
x = M{1,4}(:,1);
C = cellfun(@(m)m(:,2),M(:,4),'UniformOutput',false);
y = [C{:}];
plot(x,y)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!