Trying to output coordinates from a CSV file and plot a CoG
이전 댓글 표시
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
Mathieu NOE
2023년 1월 3일
편집: Mathieu NOE
2023년 1월 3일
hi
it would help if you share the csv file along
have you tried with csvread ?
David Gill
2023년 1월 3일
편집: David Gill
2023년 1월 3일
David Gill
2023년 1월 3일
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
2023년 1월 3일
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
2023년 1월 3일
Image Analyst
2023년 1월 3일
How about posting a screenshot of the data plotted, with an indication of where you think the centroid should approximately be?
David Gill
2023년 1월 4일
Mathieu NOE
2023년 1월 4일
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
2023년 1월 8일
Mathieu NOE
2023년 1월 9일
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
2023년 1월 9일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Offroad Autonomy for Heavy Machinery에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
