defining matrix for a loop

3 次查看(过去 30 天)
hi
i need to define a matrix to write an output.
the code i used is
txtFiles = dir('*.txt') ;
N = length(txtFiles) ;
PSDsheet = zeros( N,16);
..........................
........................
.........................
PSDsheet (n,:) = AllPSD
while im running this 'Unable to perform assignment because the size of the left side is 1-by-16 and the size of the right side is 3-by-16'.
Please help me what i need to modify.

采纳的回答

KSSV
KSSV 2021-7-29
txtFiles = dir('*.txt') ;
N = length(txtFiles) ;
PSDsheet = cell( N,1);
..........................
........................
.........................
PSDsheet{n} = AllPSD
OR
txtFiles = dir('*.txt') ;
N = length(txtFiles) ;
PSDsheet = zeros( N,3,16);
..........................
........................
.........................
PSDsheet(n,:,:) = AllPSD
Bottom line either save them into cell if you don't know dimensions or save them into 3D matrix if you know the dimensions.
You are getting error becuase, you are trying to save more number of elements than initalized for.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by