How to pre-allocate a double for following script ?

3 visualizzazioni (ultimi 30 giorni)
How to pre-allocate a variable name 'syncat' data type:(double) ,for following script. Please help. I get error while assigning as <syncat = cell(100000,2);> All other methods, which is available online are failed.
clear
clc
tic
Mmin = 4.5;
Mmax = 6.5;
Delta_M = 0.01;
a = 4.5;
b = 1;
% Annual occurrence rate of earthquakes with M >= Mmin
Lambda = 10^(a-b*Mmin);
Tmax = 100000; % Duration of the simulated catalog (years)
time = 0;
count = 0;
f = waitbar(0,'Please wait...');
while time <= Tmax
% First simulation (time of the next earthquake)
% This is the inverse of the Exponential distribution
iatime = expinv(rand(1,1),1/Lambda);
time = time + iatime;
count = count + 1;
waitbar(time/Tmax,f,[num2str(round(time/Tmax*10*100)/10),' %'])
% Second simulation (magnitude value)
m = - log10(10^(-b*Mmin)-rand(1,1)*(10^(-b*Mmin)-10^(-b*Mmax)))/b; % CDF - Mmin and Mmax
syncat(count,:) = [time m];
end
close(f)
%% Let's now see how the simulated earthquake catalog looks like
years = syncat(:,1);
magnitude = syncat(:,2);

Risposta accettata

Torsten
Torsten il 1 Ago 2022
What about
syncat = zeros(100000,2)
?
  3 Commenti
NISHANT SURESHBHAI TEJANI
However, It does not help with reducing computing time! Any suggestion ?
Stephen23
Stephen23 il 1 Ago 2022
"However, It does not help with reducing computing time! Any suggestion ?"
Get rid of the WAITBAR.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Earthquake Engineering in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by