現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
Find row and column of specific array.
4 ビュー (過去 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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)