Saving a rxcx matrix into a larger rxcy matrix

1 回表示 (過去 30 日間)
Ryan
Ryan 2022 年 7 月 19 日
編集済み: Tejas 2024 年 12 月 26 日
I currently have a system where a collect gives me 16538 by 15 columns of data as an output for every collect in the series. I am looking to save these 15 columns of data after every scan into a larger matrix so that the raw data can be accessed at a later date for analysis.
for individual 16538 by 1 data sets the following "Data(:, counter) = Spectrum;" works fine, where Data collects 16538 by counter columns until the capture ends.
Instead I am trying to find a way to save Data where the spectrum is 16538 by 15 instead. Anyone have any ideas to sort this simply?

回答 (1 件)

Tejas
Tejas 2024 年 12 月 26 日
編集済み: Tejas 2024 年 12 月 26 日
Hello Ryan,
The spectrum with a size of (16538, 15) can be incorporated into a larger matrix 'Data' by simply replacing the columns in 'Data' with the 'Spectrum' data.
Here are the steps to add 'Spectrum' data from each scan to the 'Data' matrix:
  • Start by pre-allocating the 'Data' matrix according to the total number of scans.
Data = zeros(16538, 15 * totalScans);
  • For each scan, identify the columns in the 'Data' matrix that need to be replaced with data from the 'Spectrum'.
for counter = 1:totalScans
Spectrum = rand(16538, 15); % Replace with your Specturm data
startCol = (counter - 1) * 15 + 1;
endCol = counter * 15;
Data(:, startCol:endCol) = Spectrum;
end
For a better understanding of this solution, run the following command in the MATLAB command line to access the documentation on array indexing:
>> web(fullfile(docroot, "matlab/learn_matlab/array-indexing.html"));

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by