Change values in matrix if it matches a tableObtaining matrix and column matches“Find and replace” from a matrix MATLABTrim Binary Matrix in MatLabresizing matrix and matching dataSum of groups of four in a matrixSelect a row matrix of values based on searchUsing a Matrix to Populate Every Other Value in a Columnfilling a zero matrix corresponding to row and column numbers2 values of different matrices match. Now change another value in same rowChanging data diagonally in matrix based on formula and table
Who or what determines if a curse is valid or not?
Why does a tetrahedral molecule like methane have a dipole moment of zero?
When a ball on a rope swings in a circle, is there both centripetal force and tension force?
How should I interpret a promising preprint that was never published in a peer-reviewed journal?
Parser for STL stereolithography data files
Somebody hacked my clock
Do pedestrians imitate automotive traffic?
Are there any satellites in geosynchronous but not geostationary orbits?
Will copper pour help on my single-layer PCB?
What is the function of "mal" in saying "Das nenn ich mal ein X"?
Did Hitler say this quote about homeschooling?
How do you name this compound using IUPAC system (including steps)?
How do you send money when you're not sure it's not a scam?
Last-minute canceled work-trip means I'll lose thousands of dollars on planned vacation
Three Subway Escalators
Does unblocking power bar outlets through short extension cords increase fire risk?
What is the intuition for higher homotopy groups not vanishing?
Improving an O(N^2) function (all entities iterating over all other entities)
I want light controlled by one switch, not two
Do higher dimensions have axes?
Discontinuous Tube visualization
Applying for jobs with an obvious scar
To what extent does asymmetric cryptography secure bitcoin transactions?
Are there foods that astronauts are explicitly never allowed to eat?
Change values in matrix if it matches a table
Obtaining matrix and column matches“Find and replace” from a matrix MATLABTrim Binary Matrix in MatLabresizing matrix and matching dataSum of groups of four in a matrixSelect a row matrix of values based on searchUsing a Matrix to Populate Every Other Value in a Columnfilling a zero matrix corresponding to row and column numbers2 values of different matrices match. Now change another value in same rowChanging data diagonally in matrix based on formula and table
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Hello I'm trying to do the following:
This is my table :
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
and I have a matrix [25,1].
I want to do the following: if the values in first and last columns match the numbers in the matrix, change the value to "99".
So the output should be this:
99
2
3
4
99
99
7
8
9
99
99
12
13
14
99
99
17
18
19
99
99
22
23
24
99
This is my attempt:
NT = zeros (x*y:1);
NT(:,1) = 1:x*y;
for i = 1:x*y
for j = 1
if NT(i,j) == x1(i,j)
NT(i,j) = 99;
end
end
end
matlab
add a comment |
Hello I'm trying to do the following:
This is my table :
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
and I have a matrix [25,1].
I want to do the following: if the values in first and last columns match the numbers in the matrix, change the value to "99".
So the output should be this:
99
2
3
4
99
99
7
8
9
99
99
12
13
14
99
99
17
18
19
99
99
22
23
24
99
This is my attempt:
NT = zeros (x*y:1);
NT(:,1) = 1:x*y;
for i = 1:x*y
for j = 1
if NT(i,j) == x1(i,j)
NT(i,j) = 99;
end
end
end
matlab
add a comment |
Hello I'm trying to do the following:
This is my table :
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
and I have a matrix [25,1].
I want to do the following: if the values in first and last columns match the numbers in the matrix, change the value to "99".
So the output should be this:
99
2
3
4
99
99
7
8
9
99
99
12
13
14
99
99
17
18
19
99
99
22
23
24
99
This is my attempt:
NT = zeros (x*y:1);
NT(:,1) = 1:x*y;
for i = 1:x*y
for j = 1
if NT(i,j) == x1(i,j)
NT(i,j) = 99;
end
end
end
matlab
Hello I'm trying to do the following:
This is my table :
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
and I have a matrix [25,1].
I want to do the following: if the values in first and last columns match the numbers in the matrix, change the value to "99".
So the output should be this:
99
2
3
4
99
99
7
8
9
99
99
12
13
14
99
99
17
18
19
99
99
22
23
24
99
This is my attempt:
NT = zeros (x*y:1);
NT(:,1) = 1:x*y;
for i = 1:x*y
for j = 1
if NT(i,j) == x1(i,j)
NT(i,j) = 99;
end
end
end
matlab
matlab
edited Mar 26 at 16:09
beaker
13.3k2 gold badges23 silver badges41 bronze badges
13.3k2 gold badges23 silver badges41 bronze badges
asked Mar 26 at 11:35
user11234070user11234070
143 bronze badges
143 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
This can be done very easily with ismember
. Let
A = [1 2 3 4 5; 6 7 8 9 10; 11 12 13 14 15; 16 17 18 19 20; 21 22 23 24 25];
B = (1:25).';
new_value = 99;
Then
B(ismember(B, A(:, [1 end]))) = new_value;
gives
B =
99
2
3
4
99
99
7
8
9
99
99
12
13
14
99
99
17
18
19
99
99
22
23
24
99
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55356187%2fchange-values-in-matrix-if-it-matches-a-table%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This can be done very easily with ismember
. Let
A = [1 2 3 4 5; 6 7 8 9 10; 11 12 13 14 15; 16 17 18 19 20; 21 22 23 24 25];
B = (1:25).';
new_value = 99;
Then
B(ismember(B, A(:, [1 end]))) = new_value;
gives
B =
99
2
3
4
99
99
7
8
9
99
99
12
13
14
99
99
17
18
19
99
99
22
23
24
99
add a comment |
This can be done very easily with ismember
. Let
A = [1 2 3 4 5; 6 7 8 9 10; 11 12 13 14 15; 16 17 18 19 20; 21 22 23 24 25];
B = (1:25).';
new_value = 99;
Then
B(ismember(B, A(:, [1 end]))) = new_value;
gives
B =
99
2
3
4
99
99
7
8
9
99
99
12
13
14
99
99
17
18
19
99
99
22
23
24
99
add a comment |
This can be done very easily with ismember
. Let
A = [1 2 3 4 5; 6 7 8 9 10; 11 12 13 14 15; 16 17 18 19 20; 21 22 23 24 25];
B = (1:25).';
new_value = 99;
Then
B(ismember(B, A(:, [1 end]))) = new_value;
gives
B =
99
2
3
4
99
99
7
8
9
99
99
12
13
14
99
99
17
18
19
99
99
22
23
24
99
This can be done very easily with ismember
. Let
A = [1 2 3 4 5; 6 7 8 9 10; 11 12 13 14 15; 16 17 18 19 20; 21 22 23 24 25];
B = (1:25).';
new_value = 99;
Then
B(ismember(B, A(:, [1 end]))) = new_value;
gives
B =
99
2
3
4
99
99
7
8
9
99
99
12
13
14
99
99
17
18
19
99
99
22
23
24
99
answered Mar 26 at 11:39
Luis MendoLuis Mendo
96k11 gold badges58 silver badges126 bronze badges
96k11 gold badges58 silver badges126 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55356187%2fchange-values-in-matrix-if-it-matches-a-table%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown