How to shorten my data in the struct I have?

16 Ansichten (letzte 30 Tage)
Robert  Flores
Robert Flores am 11 Sep. 2019
Beantwortet: the cyclist am 11 Sep. 2019
Hello,
I have some data that I am trying to plot, but I have way to many data points; the code takes forever to run. Therefore, I am trying to make the data smaller by using the decimate function, such that I have much less data points, but the behavior of my data doesn't change. However, when I made this for loop I get an error saying, 'Unable to perform assignment because the size of the left side is 500001-by-1 and the size of the right side is 20001-by-1'.
I want the for loop to go through each struct in my field (SBOB{1,p}) , and change the column length of two varibles that are 500001-by-1, t_data and accel_data. If anyone can help me figure how to make this for loop work with having my data cut down to 20001-by-1, it will be most appreciated, thank you.
By the way I am only doing this for SBOB right now; I will include SBridge later.
Sincerely,
Robert Flores
CODE:
clc, clear, close all
zpcstartup
%% Data of Interest
% These for loops were used in creating SBOB & SBridge
% % Let this be for BOB
% for i = [12:14,44:60,71:82]
% filename1{i} = sprintf('Z:\\BARB\\TestData\\ShockData_July2018\\Time_Histories_R2\\test0%d_filt_time.mat',i);
% SBOB{i} = load(filename1{i})
% end
% % Let this be for Bridge
% for i = [15:19,31,34,41:43,61:70,83:93]
% filename2{i} = sprintf('Z:\\BARB\\TestData\\ShockData_July2018\\Time_Histories_R2\\test0%d_filt_time.mat',i);
% SBridge{i} = load(filename2{i})
% end
load('DropTable_BOB_filtdata.mat')
load('DropTable_Bridge_filtdata.mat')
%% Decimate the data to a sample rate of 1e5
for p = 1:length(SBOB)
for h = 1:16
SBOB{1,p}.accel_data(:,h) = decimate(SBOB{1,p}.accel_data(:,h),25);
SBOB{1,p}.t_data = decimate(SBOB{1,p}.t_data,25);
end
end

Akzeptierte Antwort

the cyclist
the cyclist am 11 Sep. 2019
The problem is that you are trying to resize your variable "in place". You can't really do this in pieces.
One solution would be to define another field in your structure
SBOB{1,p}.decimated_data = zeros(20001,16);
and then in your loop, do
SBOB{1,p}.decimated_data(:,h) = decimate(SBOB{1,p}.accel_data(:,h),25);
and similarly for t_data.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by