Dynamically change variable name inside a loop in MATLAB


This script is being used for image processing by multiplying a set of 2000 images with a mask and then summing the values in each frame. These values are entered into a row vector called Intensity.

I am trying to end up with 20 row vectors called intensity1, intesity2...intensity20, is there a straight forward way to change the name of the Intensity row vector upon every loop iteration?

for m=1:20 mask=bigrating(m,m,0); for n=1:2000 I=sum(sum(imread((sprintf('image%05d.tif',n))).*(mask))); Intensity(n)=I; end save('filepath','Intensity') end


Because you wanted dynamically named intensity1, intensity2,....intensity20 etc, the following should work for you:

for m = 1:20 mask = bigrating(m,m,0) for n = 1:2000 I=sum(sum(imread((sprintf('image%05d.tif',n))).*(mask))); eval(['intensity' num2str(m) ' = I']) end save('filepath', ['intensity' num2str(m)]) end


  • Special national characters won't .split() in Python
  • How to implement language packs in PHP
  • how can i get countries states list from states table ,when i select country from countries table us
  • Using multiple POSTGRES databases and schemas with the same Flask-SQLAlchemy model
  • getting duplicated value in xsl:for tag while xml transformation
  • Read and display gray scale images in C language.
  • How to compose a matrix to perform isometric (dimetric) projection of a world coordinate?
  • Java - how to add a listener in ImageJ plugin?
  • Otsu's Thresholding Implementation not working properly
  • special add in matlab [duplicate]
  • Define A UDF with Generic Type and Extra Parameter
  • Functional way to find a pair of integers, which sum to X, in a sorted array
  • Sorting a vector multiple times
  • Python ValueError: non-broadcastable output operand with shape (124,1) doesn't match the broadc
  • Sorting vector of strings with leading numbers
  • Are there Move (_mm_move_ss) and Set (_mm_set_ss) intrinsics that work for doubles (__m128d)?
  • Plotting RDA (vegan) in ggplot
  • R: Doing t-test between pairs of factors
  • Hash function to matrix
  • Using ifelse with random variate generation in a function applied to a vector
  • Convert from DataFrame to JavaPairRDD
  • WCF Service Application returns 404 using WebGet
  • Determining if a string has been entered with a leading single quote
  • Type mismatch: cannot convert from Connection to Connection
  • Drag and Drop for imageview not working
  • Program crashes when run outside IDE
  • Most efficient way to replace lowest list values in dataframe in R
  • runtime-check whether an instance (Base*) override a parent function (Base::f())
  • Is there a package like bigmemory in R that can deal with large list objects?
  • Scala multiline string placeholder
  • How to determine if there are bytes available to be read from boost:asio:serial_port
  • Initializer list vs. initialization method
  • Why winpcap requires both .lib and .dll to run?
  • Unanticipated behavior
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • How to set the response of a form post action to a iframe source?
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • unknown Exception android
  • Can't mass-assign protected attributes when import data from csv file
  • Unable to use reactive element in my shiny app