Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

replace the 2nd and 3rd elements without the use of find

2 Ansichten (letzte 30 Tage)
Chaoyang Jiang
Chaoyang Jiang am 9 Jun. 2018
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
a=[2 3 4 1 3];
b=[1 1 0 1 0];
c=[2 3];
how to replace the 2nd and 3rd elements (c) in a(b) by 3 without the use of find? The expecting results are:
a(b)=[2 3 1];
a(b)(c)=[3 1];
The following code cannot run.
a(b)(c)=3;

Antworten (1)

James Tursa
James Tursa am 9 Jun. 2018
Hints:
1) Create a new variable to store a(b) <-- Assuming b is a logical vector here!
2) Use c to index into this variable and replace the values
3) Assign this result back into a(b)

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by