How do I replace one value of a matrix with another value from a different matrix?

6 ビュー (過去 30 日間)
Connor
Connor 2023 年 2 月 6 日
回答済み: Image Analyst 2023 年 2 月 6 日
How to you swap a variable in one matrix with another variable from a different matrix without typeing in (for example) E(1,2) = 3?
Is there a way to do it by specifying the matrix and the values position that you want to use to swap?
I have tried to say something like A(1,1)=B(2,2) but I keep getting this error:
Incorrect use of '=' operator. Assign a value to a variable using '=' and compare values for equality using '=='.

回答 (2 件)

Image Analyst
Image Analyst 2023 年 2 月 6 日
It will work but you're going to have to type something after the equals sign, like
A(1,1) = B(2,2)
otherwise how will it know the location in B and the location in A?
Show the entire actual error message, not just a snippet from it. Specifically the error message will show the line of code and you forgot to include that. Show us ALL THE RED TEXT.
It's possible you had an "if" before that. Or it's possible that B is not the same class as A. What does this show?
whos A
whos B
A(1,1) = B(2,2)

Arif Hoq
Arif Hoq 2023 年 2 月 6 日
編集済み: Arif Hoq 2023 年 2 月 6 日
I don't find any issue.please attach your data and code.
A=[3 6 8 9;1 2 5 6]
A = 2×4
3 6 8 9 1 2 5 6
B=[11 22 33 44;55 66 77 88];
A(1,1)=B(2,2)
A = 2×4
66 6 8 9 1 2 5 6

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by