How do I take the 'left' side of a matrix? (row-wise)

3 ビュー (過去 30 日間)
Niels van Dalen
Niels van Dalen 2020 年 6 月 30 日
コメント済み: Niels van Dalen 2020 年 6 月 30 日
General question:
imagine my matrix being:
a =
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
then i want to get a matrix:
b =
1 2 3
1 2 3
1 2 3
More specifically:
I have a matrix of size n x 59577, a for loop adds a new row of data to the matrix depending how many audio files are being read.
numSamples = 59577; %the length of the audio files in samples
files = [1,3]; %These numbers can be chosen (values point to a different audio file)
nLoadedFiles = length(files);
for ii = 1:nLoadedFiles
%Get the audio samples from the cell array and store them as rows in 'samples'
samples(ii,:) = audioData{files(ii)};
%Take the fft of all loaded samples
ffts(ii,:) = fft(samples(ii,:));
SSBs(ii,:) = ffts(ii(1:numSamples/2),:); %This gives: Index exceeds the number of array elements (1).
%So im looking for how to declare
SSBs = %SHOULD BE A COPY OF THE ROWS IN FFTS, BUT THEN ONLY THE FIRST HALF, IE. (1:numSamples/2)
end
Maybe the error is caused by numSamples being odd? (59577)

回答 (1 件)

KSSV
KSSV 2020 年 6 月 30 日
For your first example:
b = a(:,1:3) ;
If A is your matrix..if your first first n columns
B = A(:,1:n) ;
If you want first n rows..
C = A(1:n,:) ;
  3 件のコメント
KSSV
KSSV 2020 年 6 月 30 日
Yes theindex is a fraction..you will get error..use
SSBs{ii} = ffts(1:round(numSamples/2),:) ;
Niels van Dalen
Niels van Dalen 2020 年 6 月 30 日
Thanks for the help :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMeasurements and Spatial Audio についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by