Writing data from cell array to vectors?

9 次查看(过去 30 天)
So I'm trying to reduce my Code.
I have an Excel file, which has 15 sheets. These Sheets are saved into one cell array?
Then I'm writing all of the Sheets in an Matrix. From Matrix I'm then take two columns and write them into separate vectors.
%%%%%%%%%%%%%
%%% Matlab Code %%%
%%%%%%%%%%%%%
[~,sheet_name]=xlsfinfo('Kippen_Sweep_1-15Hz_VL-0N_0k4G-A_G05-VAQLu-li-2788347-03-S-.xlsx');
for i=1:numel(sheet_name)
Daten{i}=xlsread('Data.xlsx',sheet_name{i});
end
%%% Array to Matrix
Daten_1Hz = Daten{1,1};
Daten_2Hz = Daten{1,2};
Daten_3Hz = Daten{1,3};
Daten_4Hz = Daten{1,4};
Daten_5Hz = Daten{1,5};
Daten_6Hz = Daten{1,6};
Daten_7Hz = Daten{1,7};
Daten_8Hz = Daten{1,8};
Daten_9Hz = Daten{1,9};
Daten_10Hz = Daten{1,10};
Daten_11Hz = Daten{1,11};
Daten_12Hz = Daten{1,12};
Daten_13Hz = Daten{1,13};
Daten_14Hz = Daten{1,14};
Daten_15Hz = Daten{1,15};
%%% Matrix to Vector
Drehmoment_1Hz = Daten_1Hz(:,3);
Drehmoment_2Hz = Daten_2Hz(:,3);
Drehmoment_3Hz = Daten_3Hz(:,3);
Drehmoment_4Hz = Daten_4Hz(:,3);
Drehmoment_5Hz = Daten_5Hz(:,3);
Drehmoment_6Hz = Daten_6Hz(:,3);
Drehmoment_7Hz = Daten_7Hz(:,3);
Drehmoment_8Hz = Daten_8Hz(:,3);
Drehmoment_9Hz = Daten_9Hz(:,3);
Drehmoment_10Hz = Daten_10Hz(:,3);
Drehmoment_11Hz = Daten_11Hz(:,3);
Drehmoment_12Hz = Daten_12Hz(:,3);
Drehmoment_13Hz = Daten_13Hz(:,3);
Drehmoment_14Hz = Daten_14Hz(:,3);
Drehmoment_15Hz = Daten_15Hz(:,3);
Idealy I would have a for loop, which then would go from 1-15Hz.
But I can't get my Code to work, in the Way I would need it.
Can anybody help me with this?
Sorry for my bad explanation, I'm quit new to Matlab and my english is kinda bad since I'm from Germany.
  1 个评论
Stephen23
Stephen23 2020-11-4
编辑:Stephen23 2020-11-4
Putting meta-data (such as frequencies) into variable names is a sign that you are doing something wrong.
Splitting up data into lots of separate variables makes it harder to work with. Avoid doing this.
The MATLAB documentation specifically advises against what you are trying to do. You are going down entirely the wrong path, unless you really want to force yourself into writing slow, complex, buggy code that is difficult to debug:
The simple and very efficient approach is to use indexing. You should use indexing to access your data.

请先登录,再进行评论。

回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by