Using mat2cell in a proper way
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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?
0 Commenti
Risposte (1)
chicken vector
il 21 Apr 2023
Modificato: chicken vector
il 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 Commenti
Stephen23
il 22 Apr 2023
Modificato: Stephen23
il 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.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!