Calculating the angle between two vectors
1 次查看(过去 30 天)
显示 更早的评论
Is my code correct? I need to calculate the angle between these vectors, I would check if the command is correct!
clear all
Files=dir('*.txt');
[z,n]=size(Files);
for x=1:z
arq=load(Files(x).name);
[v,b]=size(arq);
for m=1:v;
pre_maleolo=atan2(norm(cross(arq(m,1:3)-arq(m,4:6),arq(m,7:9)-arq(m,4:6))),dot(arq(m,1:3)-arq(m,4:6),arq(m,7:9)-arq(m,4:6)));
pre_joelho=atan2(norm(cross(arq(m,4:6)-arq(m,7:9),arq(m,10:12)-arq(m,7:9))),dot(arq(m,4:6)-arq(m,7:9),arq(m,10:12)-arq(m,7:9)));
pre_quadril=atan2(norm(cross(arq(m,7:9)-arq(m,10:12),arq(m,13:15)-arq(m,10:12))),dot(arq(m,7:9)-arq(m,10:12),arq(m,13:15)-arq(m,10:12)));
pre_tronco=atan2(norm(cross(arq(m,10:12)-arq(m,13:15),arq(m,16:18)-arq(m,13:15))),dot(arq(m,10:12)-arq(m,13:15),arq(m,16:18)-arq(m,13:15)));
maleolo(m)=pre_maleolo*180/pi;
joelho(m)=pre_joelho*180/pi;
quadril(m)=pre_quadril*180/pi;
tronco(m)=pre_tronco*180/pi;
end
savefile=['angulos','.',Files(x).name];
save(fullfile('C:','TCC',savefile),'maleolo','joelho','quadril','tronco','-ASCII');
end
0 个评论
回答(1 个)
Jan
2012-11-20
Usually after arq=load(Files(x).name) the variable arq is a struct. I think, you want to use a specific field of it. If you have a different situation, please explain this explicitly.
There is no chance that we can guess if parts like "arq(m,7:9)-arq(m,4:6)" are correct or not. There is neither a documentation nor descriptive names of variables.
You forgot what you think about the correctness of your code. Do you error messages or do the results differ from your expectations? Did you create test data with known output and compared it with the results?
3 个评论
Jan
2012-11-20
@Marcelo: There is no graphical output in your code. And what exactly is "reverse" here? Does the example of the text file help to understand the problem? It is surprising that the text file does not contain any numbers.
I suggest to update the question substantially: Take into account, that we do not have the faintest idea about what you are doing. Omit all code, which is not related to the problem. Consider, that is is even for the author very hard to debug lines like this:
atan2(norm(cross(arq(m,10:12)-arq(m,13:15),arq(m,16:18)-arq(m,13:15))),dot(arq(m,10:12)-arq(m,13:15),arq(m,16:18)-arq(m,13:15)))
Without knowing what this line should compute, a debugging is impossible.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 3-D Scene Control 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!