I'm trying to find the RMSD of the numbers by taking 1-2,2-3,3-4 in a sequence ,how can i loop as such ??
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ramesh Bala
el 28 de Jun. de 2019
Comentada: Guillaume
el 30 de Jun. de 2019
I'm right now doing as such,how to form a loop by taking in the previous nos?
N = [ 55378 55344 55310 55276 55242 55208];
a = N(1,1);
b = N(1,2);
RMSDD1 = sqrt ( sum(( b-a).^2 /sum(a).^2) );
fprintf ('the RMSD value between two nos : %f\n' ,RMSDD1);
RMSDDP = RMSDD1*100;
fprintf ('the RMSD value between two nos in % : %f\n' ,RMSDDP);
a = N(1,2);
b = N(1,3);
RMSDD2 = sqrt ( sum(( b-a).^2 /sum(a).^2) );
fprintf ('the RMSD value between two nos : %f\n' ,RMSDD2);
RMSDDP = RMSDD2*100;
fprintf ('the RMSD value between two nos in % : %f\n' ,RMSDDP);
0 comentarios
Respuesta aceptada
Guillaume
el 28 de Jun. de 2019
No idea what RMSD is. In your formula,
RMSD = sqrt(sum(b-a).^2 / sum(a).^2);
none of the sum make any sense, since both a and b are scalar. sum has only one number to sum, so it is equivalent to:
RMSD = sqrt((b-a)^2 / a^2); %what was the point of the sums?
Assuming that it is the correct formula, to apply it to each element of your vector it would be:
N = [55378, 55344, 55310, 55276, 55242, 55208];
RMSD = sqrt((N(2:end) - N(1:end-1)).^ 2 ./ N(1:end-1).^2);
5 comentarios
Guillaume
el 30 de Jun. de 2019
"Comments from guilame gives me : 833,1341,1711 as RMSD results ? But the actual results shld be 19,11,5."
My code gives you exactly the same output as the one you've posted, except that it is a lot more generic (will work with any number of files) and simpler.
Output from the code you've given above:
the RMSD value between two sensor signals 1,2 @ 5,200 kHz : 833.775403
the RMSD value between two sensor signals DC @ 5,200 kHz : 83377.540327
the RMSD value between two sensor signals 1,2 @ 5,200 kHz : 1341.762683
the RMSD value between two sensor signals DC @ 5,200 kHz : 134176.268293
the RMSD value between two sensor signals 1,2 @ 5,200 kHz : 1717.228148
the RMSD value between two sensor signals DC @ 5,200 kHz : 171722.814834
You get 833, 1341 and 1717 as well.
Of course, if the formula in your code was wrong, then the formula in mine is as well. I've just implemented exactly the same in more efficient way.
As Walter pointed out, it can be implemented a bit simpler as well, by using diff.
filenumbers = [18502, 22172, 24677, 25892];
%load data as numel(filenumbers) x N matrix
filecontents = arrayfun(@(fn) load(sprintf('%d.mat', fn)), filenumbers); %this will error if the files don't all have exactly the same variable names
data = vertcat(filecontents.ans); %this will error if the files don't have an ans variable or if the ans vectors are not the same length
%calculate RMSD
RMSD = sqrt(sum(diff(data, 1) .^2, 2) ./ sum(data(1:end-1, :), 2).^2)
Más respuestas (1)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!