Filter löschen
Filter löschen

Using mat2cell in a proper way

9 Ansichten (letzte 30 Tage)
Edoardo
Edoardo am 21 Apr. 2023
Bearbeitet: Stephen23 am 22 Apr. 2023
I have a matrix with format 4822x35 doubles and 2418x35 doubles, is it possible to create cells with 10x35 cells? If yes, what should I write?
If I refer to the MATLAB documentation, the thing that I should write will gonna be like this (according to my reasoning)
>> mat2cell(A,[241.8 241.8 241.8 241.8 241.8 241.8 241.8 241.8 241.8 241.8],[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1])
this example is for 2418x35 doubles. But when I run the code, the error said that the array 1 must be positive integers. So how should I do the splitting?

Antworten (1)

chicken vector
chicken vector am 21 Apr. 2023
Bearbeitet: chicken vector am 21 Apr. 2023
When you use mat2cell, besides the first entry that is the matrix you want to modify into a cell, the other inputs give the instruction on how to divide the matrix into smaller chunks.
You can imagine a matrix as a square of non-divisible bricks.
What you are trying to do is to create a 241.8x1 matrix, meaning that you are "cutting" some of this bricks.
In other words, the dimension of a matrix must be positive integers and dividing a 2418x1 matrix into 10 subarrays is simply not possible.
You have to come up with different solutions for your problem or try post your code to seek for specific help.
Maybe interp1 might be helpful to resize the original matrix to yoru needs.
In general you want to use interp2, but you don't have any problem along the columns.
  5 Kommentare
Edoardo
Edoardo am 22 Apr. 2023
Bearbeitet: Edoardo am 22 Apr. 2023
@chicken vector to be honest the thing that I want is complex (in general).
Those 4822x35 doubles and 2418x35 doubles is the transformed EEG result (the transformation that I use is Wavelet Transform sym8). I need to divide those 4822 doubles and 2418 doubles into 10 cells because I need to divide the data into 10 minutes. The "35" comes from 35 different electrodes. Then for each electrode I need to locate in what minute the signal becomes abnormal. For example, in electrode 1, the abnormalities happened in minute 5; in electrode 2 in minute 5 and 7; in electrode 3, in minute 7 and 10, ... etc., up until all those 35 electrodes. Finally I need a thing like a truth table in order to write the results. Of course if-else commands are also needed in this case, but I haven't learnt about it for now.
So that is the reason why I ask about converting doubles to cells first, because I need to divide the values in 4822x35 doubles and 2418x35 doubles into 10 minutes first. Do you think that my approach is correct?
Actually, I can do it manually by plotting the graph and look at each of them one-by-one, but since there are 35 electrodes to be care about, it is exhausting, and I'm afraid that I miss somewhere in the middle
Stephen23
Stephen23 am 22 Apr. 2023
Bearbeitet: Stephen23 am 22 Apr. 2023
"I need to divide the data into 10 minutes"
I doubt that splitting up your data would be a good approach. Then you cannot use inbuilt tools effectively:
So far you have not told us the most important information: how do the rows of your data correspond to minutes? Were they sampled with a constant sample rate, or do you have some timestamp data?
"Of course if-else commands are also needed in this case,"
I doubt that.
Note that by assuming that you need to split data up into cell arrays and use IFs you are making this mistake:
Your task is not to split data up into a cell array. Your task is to determine when specified events occur in your data.
You should have asked about that in the first place.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by