Register to reply

Variable name matlab help

by mathsgeek
Tags: matlab, urgent, variable
Share this thread:
mathsgeek
#1
Oct2-09, 12:15 AM
P: 63
How do i change the variable, so it saves all the values, even if it must happen for 6 different variables name. This is because when i run it, it only saves the values for v_max when n=10 as this is the last iteration. How can i make all the values be saved. My coding is below:

radius=1:0.5:2.5;
total_flow_velocity=5

for n=5:1:10
v_max = (total_flow_velocity.*(1+n).*(1+(2.*n)))./((2.*pi)*((radius.*n).^2))
end

Thanks
Phys.Org News Partner Science news on Phys.org
Wildfires and other burns play bigger role in climate change, professor finds
SR Labs research to expose BadUSB next week in Vegas
New study advances 'DNA revolution,' tells butterflies' evolutionary history
JeroenS
#2
Oct2-09, 03:06 AM
P: 5
probably the best way is to store them in a vector. You define a vector called v_max with a length equal to the amout of values, in your case that is 6:

v_max=[1:6];

then you can store each value in one of the positions of the maxtrix like:

for n=5:1:10
v_max(1,n-4) = (total_flow_velocity.*(1+n).*(1+(2.*n)))./((2.*pi)*((radius.*n).^2))
end

I used n-4 to define column number 1 because you start with n=5. After that you can recall any value by typing:

v_max(1,1) .... v_max(1,6)

good luck!
mathsgeek
#3
Oct2-09, 03:34 AM
P: 63
ive tried it but i get the error "Subscripted assignment dimension mismatch." ? Also why did u do vmax=[1:6] because for each r value ive made it so i get an answer at each n value, so shouldnt the matrix be a 6x4?

ApexOfDE
#4
Oct2-09, 08:00 AM
ApexOfDE's Avatar
P: 122
Variable name matlab help

JeroenS' code has a mistake inside for loop. v_max(1,n-4) ==> indicate member (1, n-4) of array v_max. However, in the calculation, he forgot to delete the operator for array: (radius.*n). This operator (.*) will return an array radius multipled by n. So, in the left-side, you have 1 variable, not an array but in right side, there is an array. That's the reason matlab throws an error.

My code is:

vM = [];
j = 0;

radius = 1 : 0.5 : 2.5;
tfv = 5;

for n = 5 : 1 : 10
    j = j + 1;
    nR = 2 * pi * (radius * n).^2;
    vM(j, :) = (1 + n) * (1 + 2*n) * tfv ./ nR;
end
Hope this help.

p/s: i am totally confused when i read your code. There are many unnecessary parentheses and operators.
mathsgeek
#5
Oct2-09, 06:41 PM
P: 63
Thanks so much, yeh i don't know why i use so many brackets and that, buts it because im use to the calculator and have only been learning MATLAB for a few weeks now :P but im beginning to learn to use less brackets :P


Register to reply

Related Discussions
MATLAB - changing variable name with each iteration? Math & Science Software 16
Matlab: Use string variable as variable name Math & Science Software 5
MATLAB char array with variable names Math & Science Software 2
Matlab user input variable name Math & Science Software 1
Stochashic variable result(Please verify) Urgent Calculus & Beyond Homework 0