How can i solve this array question?

5 Ansichten (letzte 30 Tage)
Emma Swaggy
Emma Swaggy am 21 Mai 2017
Kommentiert: Walter Roberson am 7 Apr. 2018
write a program that asks the user to enter integer numbers and store the numbers in a two dimensional array, then replace any 9 digit by 0 digit. After that Change the numbers that are in odd row positions by the even row positions.
  1 Kommentar
Thomas Nguyen
Thomas Nguyen am 7 Apr. 2018
This is very unclear + no example of any sort => can't help unless you be more specific

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 21 Mai 2017
The easiest way to replace 9 digits with 0 digits is to int2str() the number, store the result, use logical indexing to find the '9' characters, store '0' characters instead, then str2double() the string after replacement.
Example:
t = sprintf('%d', A_Number);
t(t == '7') = '8';
str2double(t)
  3 Kommentare
Walter Roberson
Walter Roberson am 22 Mai 2017
I just showed you how to do it with the example of replacing 7 with 8. You can make the obvious changes.
Walter Roberson
Walter Roberson am 7 Apr. 2018
temp = arrayfun(@(x) sprintf('%d', x), YourArray, 'uniform', 0);
now you can proceed through the entries in the cell array temp making the substitutions, producing a new cell array. Then you can str2double() the new cell array to get back to a numeric array.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by