Filter löschen
Filter löschen

Converting R code into Matlab code

1 Ansicht (letzte 30 Tage)
noa goldman
noa goldman am 4 Feb. 2020
Beantwortet: Jeff Miller am 5 Feb. 2020
Hi everyone,
I'm starting to learn matlab.
I would love if anyone could help me write this code in matlab:)
speed = [28 -44 29 26 27 22 23 33 16 24 40 21 31 34 -2 25 19];
newSpeed= speed-mean(speed)+33.02;
> bstrap <- c()
> for (i in 1:1000){
+ newsample <- randsample(newspeed, 20, replace=T)
+ bstrap <- c(bstrap, mean(newsample))}
> hist(bstrap)
p= (sum(bstrap < 21.75) + sum(bstrap > 44.29))/1000

Antworten (1)

Jeff Miller
Jeff Miller am 5 Feb. 2020
I think MATLAB has a built-in function that you can use instead of the R for loop. Try just:
newSpeed= speed-mean(speed)+33.02;
bstrap = bootstrp(1000,@mean,newspeed)
histogram(bstrap);

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by