How can i solve this array question?

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

Thomas Nguyen
Thomas Nguyen 2018년 4월 7일
This is very unclear + no example of any sort => can't help unless you be more specific

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2017년 5월 21일

0 개 추천

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

Emma Swaggy
Emma Swaggy 2017년 5월 22일
Thanks for your reply but I still don't know how to solve it because I don't have any background about it . So if you know how to do it , i will appreciate .
Walter Roberson
Walter Roberson 2017년 5월 22일
I just showed you how to do it with the example of replacing 7 with 8. You can make the obvious changes.
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2017년 5월 21일

댓글:

2018년 4월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by