Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Creating a 3 Dimensional Array with Elements Automatically Filled In

1 vue (au cours des 30 derniers jours)
saad khalid
saad khalid le 14 Juil 2015
Clôturé : MATLAB Answer Bot le 20 Août 2021
I'm trying to create a 3 Dimensional array. The program I'm running has 3 inputs. "a" needs to go from .08 and .12 in increments of .01, "b" needs to go from 4 to 6 in increments of 1, and "c" needs to go from .7 to .9 in increments of .1. I thought this would be simple enough simply using the colon operator, but I'm having a hard time with this.
I know this could also be done with 3 for loops, however, I think that using a premade matrix with the values will be faster? In case I wasn't clear, the idea is for the program to run with a = .08, b = 4, and c = .7, and then it will increment c to .8 and then .9, and then it will increment b to 5, and start with c = .7 again, until it has gone through all of these cases up to a = .12.
Thank you!

Réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 14 Juil 2015
Modifié(e) : Azzi Abdelmalek le 14 Juil 2015
Maybe you need to use meshgrid function
a=0.8:0.1:1.2
b=4:1:6
c=0.7:0.1:0.9
[x,y,z]=meshgrid(a,b,c)
out=[x(:) y(:) z(:)]

Community Treasure Hunt

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

Start Hunting!

Translated by