이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Find row and column of specific array.
조회 수: 6 (최근 30일)
이전 댓글 표시
armin m
2021년 11월 28일
Hi. I want to find row and column of array in matrix. But with out using the find function. Because it finds the same numbers and put them in specific matrix. I want the code like this:
C=0
for j=1:10
C=C+1
[Rownum, colnum]=Q(j)
R(C,1)=Rownum
R(C,2)=colnum
end
채택된 답변
Image Analyst
2021년 11월 28일
What is Q?
To get the rows and columns try the meshgrid() function:
x = 1 : 5; % 5 columns.
y = 1 : 4; % 4 rows.
[columnsArray, rowsArray] = meshgrid(x, y)
댓글 수: 24
armin m
2021년 11월 28일
I have 2016. Q is a matrix that i had maked before. It is not imp9rtant what is Q is!
Image Analyst
2021년 11월 28일
편집: Image Analyst
2021년 11월 28일
So then, did my solution do what you want?
Can you give a small example?
Maybe you want
out = reshape(Q, [], 2)
armin m
2021년 11월 28일
편집: Image Analyst
2021년 11월 28일
I explained first
Q=[5 7 8 9 0 7 6 7 88]
C=0
for j=1:10
if Q(j)~=0
C=C+1
[Rownum,colnum]=Q(j)
R(C,1)=Rownum
R(C,2)=colnum
end
end
If i want explain simply, i want make matrix of row and column of array in specific arrangment of j=1:10
Image Analyst
2021년 11월 28일
I still don't understand when you say
[Rownum,colnum]=Q(j)
That won't work. Q(j) returns a single number, not two numbers.
thisValue = Q(j); % Works.
armin m
2021년 11월 28일
I want a code to do what i said in place of "[Rownum,colnum]=Q(j)" "i know this does not work"
armin m
2021년 11월 28일
For e.g . In run mode: j=4 Q(4)=9 C=4 Row and column > [1,4] So R(4,1)=1 R(4,2)=4 If i wanna say simply. I wanna a code which take row and column of Q(j) in each iteration.
Image Analyst
2021년 11월 28일
Why do you not want to use the find function? Do you want to do this
C=0
R = zeros(size(Q, 1), 2);
for j = 1 : length(Q)
if Q(j) == j
C=C+1
Rownum = 1;
colnum = j;
R(C,1)=Rownum;
R(C,2)=colnum;
end
end
armin m
2021년 11월 28일
Beacause it take vector instead of number if it find same numbers. For example i takes Row 1 1 1 and col 2 6 8 for number 7.
Image Analyst
2021년 11월 28일
Please give your expected outputs Rownum and colnum so I can try to figure out what you want, because your explanations are just not getting through to me.
armin m
2021년 11월 28일
Thank you for spending time. I have a matrix which has many zero array. I want find non zero array and put their row and column in specific matrixes. May be i have weakness in explanation but ot is first time i have difficulty in problem explanation.
armin m
2021년 11월 28일
I have this matrix Q=[1,3,5;7,8,9;8,77,0;8,0,9] I want to put row of non 0 arrays in first column of Matrix R and column of these arrays in second column of matrix R.
Image Analyst
2021년 11월 28일
It's really hard working with you (I'm about to give up).
OK, please say what you expect R to be (you forgot to give your desired output).
Image Analyst
2021년 11월 28일
편집: Image Analyst
2021년 11월 28일
I first started to do it vectorized but because you're arranging things and ordering things in a non-standard order it just because so cryptic and complicated with transposing things, etc. that I decided to do it with a simple, intuitive and eacsy to follow for loop:
Q=[1,3,5;7,8,9;8,77,0;8,0,9]
Q = 4×3
1 3 5
7 8 9
8 77 0
8 0 9
% R=[1,1;1,2;1,3;2,1;2,2;2,3;3,1;3,2;4,1;4,3] % Desired output.
% Get size of Q.
[rows, columns] = size(Q)
rows = 4
columns = 3
counter = 1;
for row = 1 : rows
for col = 1 : columns
if Q(row, col) ~= 0
R(counter, 1) = row;
R(counter, 2) = col;
counter = counter + 1;
end
end
end
R
R = 10×2
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
4 1
4 3
Image Analyst
2021년 11월 28일
It gives you the desired output for the one example you gave. So is there anything still wrong with it, such that you haven't Accepted the answer yet? Tell me what it is and I'll fix it.
Image Analyst
2021년 11월 29일
Since you say it was the best answer, could you please click the "Accept this answer" link? Thanks in advance.
The cost of writing MATLAB code varies a lot. About 10 years ago we asked the Mathworks and their rate then was $190 per hour. You can get computer programmers to write code for around $90 - $150 per hour here in the US but that's just in general for languages like C and Python and Java. We did hire one local engineering firm that did MATLAB programming for us at around $90 per hour but then I think their latest price was more like $130 per hour.
You can try fiverr.com and get freelance MATLAB programmers for very much cheaper, though if their quality is like what I see here by questioners in the Answers forum, it's not going to be professional quality.
armin m
2021년 11월 29일
I asked it because i write program code for some one . It is for electrical engeneering. I wanna know how much should i take from him!!!
Image Analyst
2021년 11월 29일
@armin m, I don't know what the going rate is for custom programming in your country is.
"i write" doesn't make too much sense. It would be either
- "I am writing" meaning you have already begun and are currently writing for him.
- "I wrote" meaning you finished writing and are all done.
- "I will write" meaning you have not yet started to write but will write for him in the future.
As you can imagine, the hourly rate varies a lot from country to country. Usually you'll give them a cost estimate before you begin work so you also have to estimate the time it will take you to do the job.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)