How to perform matrix math
Hello all, I currently have a code to look at delta distances in a .csv file and ouput a new csv files with these a summation of these distances for each of the three columns. This code looks at three columns in a .csv files, subtracts the second row from the first row and continues this calculation down all the rows. I have had the chance to look at some of this distance data and it looks good but I need to tweak my calculation. Where I have S = sum(abs(diff(M(:,2:4),1,1)),1).
I would like to continue this method of subtracting the second line from the first and moving down. But I need an intermediate step (or 2) where the values are subtracted values are squared. The that row of values would be added up and the sqrt of that would be taken.That end value would be added to the end values of that operation performed down the rows.
I have attached an image that explains this clearer (I hope). Its a way of doing the distance formula. I just need to loop it for 500 x y and z coordinates. I will also attach an example file of the data in .csv form. Thank you, any help is much appreciated!
clc
% appropriate dir() call that returns info
% about the files you want to process:
fn = dir(‘C:UserslucasarsenithDesktopData/*.csv’); % this call returns info about .csv files in the current directory;
% you may need to modify it to work for your file locations
% (see dir documentation)
% number of files:
N_files = numel(fn);
% pre-allocate results matrix (one row per file, 3 columns):
results = zeros(N_files,3);
% read and process each file:
for ii = 1:N_files
% read the file starting from line 10:
M = readmatrix(fullfile(fn(ii).folder,fn(ii).name));
% process columns 2-4 of the file’s data:
S = sum(abs(diff(M(:,2:4),1,1)),1);
% store the result:
results(ii,:) = S;
end
% write the results file (can be located anywhere):
writematrix(results,’C:UserslucasarsenithDesktopPlot.csv’)Hello all, I currently have a code to look at delta distances in a .csv file and ouput a new csv files with these a summation of these distances for each of the three columns. This code looks at three columns in a .csv files, subtracts the second row from the first row and continues this calculation down all the rows. I have had the chance to look at some of this distance data and it looks good but I need to tweak my calculation. Where I have S = sum(abs(diff(M(:,2:4),1,1)),1).
I would like to continue this method of subtracting the second line from the first and moving down. But I need an intermediate step (or 2) where the values are subtracted values are squared. The that row of values would be added up and the sqrt of that would be taken.That end value would be added to the end values of that operation performed down the rows.
I have attached an image that explains this clearer (I hope). Its a way of doing the distance formula. I just need to loop it for 500 x y and z coordinates. I will also attach an example file of the data in .csv form. Thank you, any help is much appreciated!
clc
% appropriate dir() call that returns info
% about the files you want to process:
fn = dir(‘C:UserslucasarsenithDesktopData/*.csv’); % this call returns info about .csv files in the current directory;
% you may need to modify it to work for your file locations
% (see dir documentation)
% number of files:
N_files = numel(fn);
% pre-allocate results matrix (one row per file, 3 columns):
results = zeros(N_files,3);
% read and process each file:
for ii = 1:N_files
% read the file starting from line 10:
M = readmatrix(fullfile(fn(ii).folder,fn(ii).name));
% process columns 2-4 of the file’s data:
S = sum(abs(diff(M(:,2:4),1,1)),1);
% store the result:
results(ii,:) = S;
end
% write the results file (can be located anywhere):
writematrix(results,’C:UserslucasarsenithDesktopPlot.csv’) Hello all, I currently have a code to look at delta distances in a .csv file and ouput a new csv files with these a summation of these distances for each of the three columns. This code looks at three columns in a .csv files, subtracts the second row from the first row and continues this calculation down all the rows. I have had the chance to look at some of this distance data and it looks good but I need to tweak my calculation. Where I have S = sum(abs(diff(M(:,2:4),1,1)),1).
I would like to continue this method of subtracting the second line from the first and moving down. But I need an intermediate step (or 2) where the values are subtracted values are squared. The that row of values would be added up and the sqrt of that would be taken.That end value would be added to the end values of that operation performed down the rows.
I have attached an image that explains this clearer (I hope). Its a way of doing the distance formula. I just need to loop it for 500 x y and z coordinates. I will also attach an example file of the data in .csv form. Thank you, any help is much appreciated!
clc
% appropriate dir() call that returns info
% about the files you want to process:
fn = dir(‘C:UserslucasarsenithDesktopData/*.csv’); % this call returns info about .csv files in the current directory;
% you may need to modify it to work for your file locations
% (see dir documentation)
% number of files:
N_files = numel(fn);
% pre-allocate results matrix (one row per file, 3 columns):
results = zeros(N_files,3);
% read and process each file:
for ii = 1:N_files
% read the file starting from line 10:
M = readmatrix(fullfile(fn(ii).folder,fn(ii).name));
% process columns 2-4 of the file’s data:
S = sum(abs(diff(M(:,2:4),1,1)),1);
% store the result:
results(ii,:) = S;
end
% write the results file (can be located anywhere):
writematrix(results,’C:UserslucasarsenithDesktopPlot.csv’) matrix, matrices, mathematics MATLAB Answers — New Questions