how to enter equation into matrix column and refer to adjacent column.
Mostrar comentarios más antiguos
Hi all. I am a Matlab beginner trying to find full width half max. Below is my code. I start with my .csv file, identify x- and y-values, fit a gaussian curve, and find half max. Next, I added x-values at evenly spaced small increments to a column in a matrix (defined as A). I want the second column (B) to find the y-values at the given x-values using the equation found with the gaussian fit (in other words, the x-value at a given row will be used in the equation to find the y-value in the adjacent column). I am stuck on the for loop here. Then, I think I can use the "find" command to find my 2 x-values to find the full width, but this may need some help too. Thank you for your help!
data = load ('Practice.csv');
datax = data(:,2);
datay = data(:,5);
f = fit(datax, datay,'gauss1')
plot(f,datax,datay)
yfitted = feval(f,datax);
hold on
[ypk] = findpeaks(yfitted)
HalfMax = 0.5*ypk
Matrix = zeros(2,1000);
A = Matrix(1,:);
for A =1:1000;
x1= 0;
x2= 1.1;
n = 1000;
A = linspace(x1, x2, n);
end;
B = Matrix(2,:); %%this is where I need help with a for loop please!
index1 = find(B <= HalfMax, 1, 'first');
index2 = find(B >= HalfMax, 1, 'last')
fwhm = index2-index1
3 comentarios
Walter Roberson
el 15 de Dic. de 2017
Your code
A = Matrix(1,:);
for A =1:1000;
x1= 0;
x2= 1.1;
n = 1000;
A = linspace(x1, x2, n);
end;
does not make any sense. You create a variable A from row 1 of Matrix, which is fine it itself. Then on the next line you have for A -1:1000, which is going to cause A to be assigned the scalar values 1, 2, 3, and so on, up to 1000, one at a time. Then at the end of your loop you have A = linspace(x1, x2, n); which attempts to overwrite your for A with a new result. This is a third use for A, which is confusing to say the least. You are also doing the same assignment every iteration of the for A loop, so there is no point in using a loop ???
Emily Pendleton
el 15 de Dic. de 2017
Walter Roberson
el 15 de Dic. de 2017
Perhaps you just want
A = linspace(0, 1.1, 1000);
Matrix(1,:) = A;
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Matrices and Arrays en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!