How to save all the values of the matrix

조회 수: 1 (최근 30일)
Conner Carriere
Conner Carriere 2021년 2월 5일
편집: the cyclist 2021년 2월 5일
I need to save the output [xi ,yi, P] in a 9x3 matrix
this is the code i currently have
for v = 1:9
CN = centroids(v,:); %Which Row
x = CN(1);
y = CN(2);
[xiv,yiv,P] = impixel(rgbG,x,y); %rgbG is the image that i am getting pixel color from
end
This is is i want the output to look like
[xi1,yi1,P1]
[xi2,yi2,P2]
[xi3,yi3,P3].......
So on so forth
thank you!

채택된 답변

the cyclist
the cyclist 2021년 2월 5일
Here is a simple adaptation of your code:
M = zeros(9,3);
for v = 1:9
CN = centroids(v,:); %Which Row
x = CN(1);
y = CN(2);
[xiv,yiv,P] = impixel(rgbG,x,y); %rgbG is the image that i am getting pixel color from
M(v,:) = [xiv, yiv, P];
end
  댓글 수: 2
Conner Carriere
Conner Carriere 2021년 2월 5일
Thank you for your quick response, I get a error, "unable to preform assignmanet because the size of the left side is 1-by-3 and the size of the right side is 1-by-5"
the cyclist
the cyclist 2021년 2월 5일
편집: the cyclist 2021년 2월 5일
If that output is 1x5, then it cannot be stored in a row of a 9x3 matrix. You could instead define M as a 9x5 matrix, or use a cell array.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by