Trying to output coordinates from a CSV file and plot a CoG
Mostra commenti meno recenti
Hi, I am trying to plot the CoG of 3 body landmarks stored in coordinates within a CSV file. However before I can plot the CoG, I need to import the CSV coordinates successfully for which I am struggling to acheive. Please see the attached matlab file and respond with any advice. Thanks. I am running Matlab on windows 11.
12 Commenti
Mathieu NOE
il 3 Gen 2023
Modificato: Mathieu NOE
il 3 Gen 2023
hi
it would help if you share the csv file along
have you tried with csvread ?
David Gill
il 3 Gen 2023
Modificato: David Gill
il 3 Gen 2023
David Gill
il 3 Gen 2023
I cannot figure out what you are calculating, however using either readtable or readmatrix will be easier than what you’re currently doing —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1250332/object_cropDLC_resnet50_3_landmarks_for_whiskersDec13shuffle1_1030000.csv')
file = websave('plotting_CoG','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1250297/plotting_CoG.m')
type(file)
M = table2array(T1(:,2:end))
ColumnMeans = mean(M)
Then do the other calculations on those values, if necessary. (I used readtable and then table2array here because I wanted to see what was in the table.)
.
Mathieu NOE
il 3 Gen 2023
your code is correct (if the intention was to have one CoG per landmark)
all the best
minor graphical output modifications :
% Read the data from the file into a matrix
data = csvread('object_cropDLC_resnet50_3_landmarks_for_whiskersDec13shuffle1_1030000.csv', 3, 0);
% Extract the x & y coordinates for the body landmarks from the matrix:
x1 = data(:,1);
y1 = data(:,2);
x2 = data(:,3);
y2 = data(:,4);
x3 = data(:,5);
y3 = data(:,6);
% Next, calculate the CoG of the body landmarks by averaging the x & y coordinates using the 'mean' function
CoGx = mean([x1 x2 x3]);
CoGy = mean([y1 y2 y3]);
% Plot the landmarks using the scatter function
figure;
scatter(x1, y1, 'r', 'o','filled');
hold on;
scatter(x2, y2, 'g', 'o','filled');
scatter(x3, y3, 'b', 'o','filled');
plot(CoGx, CoGy, '*k', 'Markersize',15);
legend({'Landmark 1', 'Landmark 2', 'Landmark 3', 'CoG'});
David Gill
il 3 Gen 2023
Image Analyst
il 3 Gen 2023
How about posting a screenshot of the data plotted, with an indication of where you think the centroid should approximately be?
David Gill
il 4 Gen 2023
Mathieu NOE
il 4 Gen 2023
simply change these lines
CoGx = mean([x1 x2 x3]);
CoGy = mean([y1 y2 y3]);
to
CoGx = mean([x1; x2; x3]);
CoGy = mean([y1; y2; y3]);
now you have 1 coG
David Gill
il 8 Gen 2023
Mathieu NOE
il 9 Gen 2023
hello
seems to me you have another post dedicated to this video processing issue (is not my expertise area I apologize)
maybe Image Analyst is again keen to help you on that topic
David Gill
il 9 Gen 2023
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Offroad Autonomy for Heavy Machinery in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
