Hi all, I'm a native C programmer and am having a hard time understanding Matlab's behavior.
I have three arrays:
sample.currtargdist (2252 x 1)
sample.targloc (1 x 2552)
distance (6 x 2252)
I can't figure out why this code results in a 2252 x 2252 matrix:
for s = 1:setsize;
distance(s,:) = sqrt((sample.RIGHT_GAZE_X-loc(s).x).^2+(sample.RIGHT_GAZE_Y-loc(s).y).^2);
end
sample.currtargdist = distance(sample.targLoc,:);
When I try something like a '1' instead of ':', I just get the first column of the matrix. I want just the first row of the output matrix.

댓글 수: 6

Azzi Abdelmalek
Azzi Abdelmalek 2015년 7월 8일
편집: Azzi Abdelmalek 2015년 7월 8일
This is not clear, what is sample.RIGHT_GAZE_X-loc? what is the value of setsize?
Nick G
Nick G 2015년 7월 8일
it's a measure of eyegaze position. It's in a 1 x 2552 array. Set size is 6. I'm measuring the distance of eyegaze from items on a screen.
Jan
Jan 2015년 7월 8일
Which one is "the output matrix"?
Nick G
Nick G 2015년 7월 8일
sample.targcurrdist
Nick G
Nick G 2015년 7월 8일
sample.targloc is an index that can be used to tell which distance value to pull
Stephen23
Stephen23 2015년 7월 8일
편집: Stephen23 2015년 7월 8일
What are sample.RIGHT_GAZE_X, sample.RIGHT_GAZE_Y, setsize, loc.x and loc.y? If they are variables, what sizes are they?
"this code results in a 2252 x 2252 matrix": which variable is the output?

댓글을 달려면 로그인하십시오.

 채택된 답변

Jan
Jan 2015년 7월 8일

0 개 추천

I want just the first row of the output matrix.
Perhaps you mean this:
sample.currtargdist = distance(sample.targLoc(1), :);
If targLoc has the size 1 x 2552 and distance is 6x2552, then distance(targloc,:) is expected to be 2552x2552 - or a bug, if the elements of targloc exceed the values 1:6.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2015년 7월 8일

0 개 추천

Probably, the value of setsize is 2252, or maybe in your code, you have pre-allocated the variable distance with zeros(2252,2252)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2015년 7월 8일

편집:

2015년 7월 8일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by