Azzera filtri
Azzera filtri

For loop and indexing combined?

9 visualizzazioni (ultimi 30 giorni)
Tom il 10 Gen 2012
I think I'm nearly there with this code.
close all;
clear all;
for n=1:5000;
What I actually want is for the code to repeat for each value of x - instead of just for the first indexed value - x(1) - as it is now.
Right now, w, is correct for x(1). Is it possible to set up a new outer for loop, which uses subsequent values of x ie. x(1), x(2) etc. instead of just using x=1,2,3,4..?

Risposta accettata

Walter Roberson
Walter Roberson il 10 Gen 2012
Yes, you had a suitable nested loop in one of your previous versions of this code.
Note: you never use iter so you might as well get rid of it.

Più risposte (1)

Tom il 10 Gen 2012
Okay - I've not come across a few of these things before. I hope you don't mind if just fire off a few questions about it.
What does the .' do aster n=(1:5000)? Why the p1 and p2? What is bsxfun? and @times?
On a different note, Mathematica has the ability to make a graph which will play in real time - so you can have an extra variable - time, t maybe. Does Matlab have anything similar? At the moment I'm looking at either doing a series of graphs for progressive values of time, t or trying a surf graph.
Many thanks, Tom
  1 Commento
Walter Roberson
Walter Roberson il 10 Gen 2012
The .' is transpose, converting the row vector (1:5000) in to a column vector.
bsxfun is the Binary Scalar Expansion Function routine; see your documentation.
@times is a function handle to the built-in element-by-element multiplication routine more commonly known as .*
For animation, please see

Accedi per commentare.


Community Treasure Hunt

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

Start Hunting!

Translated by