Skip to Main Content Skip to Search
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Doug’s Pick of the Week

August 20th, 2007

MATLAB Basics video: Storing data in a matrix from a loop

I was recently answering a question that came in from a MATLAB user on this blog. In the end, the question was really one where he was doing a calculation and storing the result in scalar Y. When he was done with the loop, he only had the final value of Y but not all of them that he had calculated on the way. The solution to this was to store each value of Y into a vector. This video is meant for new users to show how to do that.

If you would rather download the video, you can get it from the File Exchange.

Also note, that I have been reformatting these videos and tagging them as videos. If you click on videos under categories to the right, you can see all the videos in one place.
video.jpg

Other videos have been gathered here:
http://blogs.mathworks.com/pick/category/video/

Other MATLAB Basics posts have been gathered here:
http://blogs.mathworks.com/pick/category/matlab-basics/

2 Responses to “MATLAB Basics video: Storing data in a matrix from a loop”

  1. kay replied on :

    Hi,
    At the end of the video you mentioned that you can do this with matrices by creating a 3D matrix. What would the indices look for that for say a 4×4 matrix?
    Y(4,4,i) ?

  2. Doug replied on :

    Kay,

    They would look like this:

    >> a = rand(4,4,2)
    a(:,:,1) =
    0.1524 0.0782 0.0046 0.0844
    0.8258 0.4427 0.7749 0.3998
    0.5383 0.1067 0.8173 0.2599
    0.9961 0.9619 0.8687 0.8001
    a(:,:,2) =
    0.4314 0.1455 0.5499 0.3510
    0.9106 0.1361 0.1450 0.5132
    0.1818 0.8693 0.8530 0.4018
    0.2638 0.5797 0.6221 0.0760
    >> a(1,2,2)
    ans =
    0.1455

    Doug

Leave a Reply


Doug Hull is an Application Engineer at The MathWorks. A MATLAB user since 1994, he gets paid to live, eat, and breathe MATLAB! This blog is dedicated to promoting the File Exchange by highlighting files and original video content.



  • Moran: Hi Chris, I tried everything I could think of, and have sent several observations about this bug to support,...
  • odessit: Hello, I have compiled standalone application with deploytool. It would work fine, but the error is in...
  • Duane Hanselman: FYI… % strmatch replacements % strmatch is obsolete, strncmp and strcmp are built in % case...
  • Doug: Duane, I just looked, I did not see an m-lint warning against STRMATCH in 2008a. However, I seem to recall what...
  • hashem: Hi Doug, I built a GUI and write a help for it in “chm” (compiled HTML file) format, and I...
  • Tim Davis: I left out the comments in the code, above. Most of the functions should be familiar to most MATLAB users....
  • Tim Davis: I was a little confused by all the back-and-forth discussion of zero blocks. Is a block of zeros to be...
  • Tim Davis: Try this one. It doesn’t require any toolboxes, just “sparse” and “dmperm” ....
  • Duane Hanselman: Did anyone ever try replacing strmatch with strcmp (or its siblings as needed)? I recall mlint...
  • jiro: @Daniel, We do use the hardware, but we don’t expose the supersampling feature through that path, so if...

These postings are the author's and don't necessarily represent the opinions of The MathWorks.

Related Topics