필터 지우기
필터 지우기

Using mat2cell in a proper way

조회 수: 9 (최근 30일)
Edoardo
Edoardo 2023년 4월 21일
편집: Stephen23 2023년 4월 22일
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?

답변 (1개)

chicken vector
chicken vector 2023년 4월 21일
편집: chicken vector 2023년 4월 21일
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
Edoardo
Edoardo 2023년 4월 22일
편집: Edoardo 2023년 4월 22일
@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 2023년 4월 22일
편집: Stephen23 2023년 4월 22일
"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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by