How to seperate a matrix into several parts and give names each of them?

1 次查看(过去 30 天)
Hi; I have a matrix which contain 270000 rows and 1column. It is a time domain data. I will do fast fourier transform but before fft I want to divide it several parts according to window length of spectrum. For example; I want to divide it as 1:20 000, 20 001:40 000, 40 001:60 000, ...That means first variable consist of the first 20 000 values of matrix and the second will be the second 20 000 of matrix and so. Then, I will apply fft to each of them. How fast can I do this? Firstly, I thought that I need to create several variable names and assign values (1:20 000) to each of them. I can I do this or what do you suggest?
  1 个评论
Stephen23
Stephen23 2018-6-13
编辑:Stephen23 2018-6-13
"...I thought that I need to create several variable names and assign values (1:20 000) to each of them."
You could do this, but only if you want to force yourself into writing slow, complex, buggy code that is hard to debug, and want to make accessing your data more difficult. Read this to know why:
"...or what do you suggest?"
Just use indexing. Indexing is simple, neat, and very very efficient. Split your data into one cell array, or simply access different parts of a numeric matrix using indexing. Either way you can write simple, efficient code.

请先登录,再进行评论。

回答(1 个)

John D'Errico
John D'Errico 2018-6-13
Don't do it.
There are MANY better ways to solve this. For example, convert your vector (via a simple reshape) into an array. I'll assume you want blocks of length 10000, since there would be exactly 13.5 blocks of length 20000.
Anew = reshape(A,10000,27);
Or, create a cell array. You can use mat2cell to do the conversion.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by