フィルターのクリア

Nested For Loop Puzzle

3 ビュー (過去 30 日間)
Samuel Awuah Botwe
Samuel Awuah Botwe 2012 年 4 月 18 日
please can anyone help me solve this Mats lab assignment
Q.Nested for loop that can solve this puzzle
T H I S W A T S O A H G G G D T
thank you
  5 件のコメント
Jan
Jan 2012 年 4 月 18 日
The program is called "Matlab".
The question is not clear. There is no obvious way to "find this puzzle". And this does not concern the Matlab implementation, but it is simply not defined, what you should do with these 16 characters.
Samuel Awuah Botwe
Samuel Awuah Botwe 2012 年 4 月 18 日
THIS WHAT I FIGURED OUT BUT GET AN ERROR CAN U PLEASE CHECK THE CODES FOR ME
m=[T,H,I,S;W,A,T,S;O,A,H,G;G,G,D,T]
l=size(m)
for i=1:l(1)
for j=1:l(2)
m(i,j) = m(i,j) * 2;
end
end
JUST AS THIS WORKS OUT AND DISPLAYS,HOW DO I MAKE IT DISPLAY IN ALPHABETS.....PLEASE TRY THIS CODE FOR ME....
m=[1,2,3,4;5,6,7,8;9,10,11,12]
l=size(m)
for i=1:l(1)
for j=1:l(2)
m(i,j) = m(i,j) * 2;
end
end

サインインしてコメントする。

回答 (3 件)

Sean de Wolski
Sean de Wolski 2012 年 4 月 18 日
Golf:
reshape(['THISWATSOAHGGGDT'],4,4)'
Okay with for-loops:
for ii = 1
for jj = 1
m = reshape(['THISWATSOAHGGGDT'],4,4)';
end
end
  3 件のコメント
Sean de Wolski
Sean de Wolski 2012 年 4 月 18 日
See the edit. Now with nested FOR-loops!
Thomas
Thomas 2012 年 4 月 18 日
:) Now why did I not think about it.. I do not know how I would grade a student if they returned an answer like yours above..
Technically they used nested for loops.. :)

サインインしてコメントする。


Thomas
Thomas 2012 年 4 月 18 日
You are on the right track, to get alphabets..
try
%this is your input
a=['T' 'H' 'I' 'S' 'W' 'A' 'T' 'S' 'O' 'A' 'H' 'G' 'G' 'G' 'D' 'T']
% You need the two for loops.. that you have created above.. however you have to make sure you get the length of the loops rights..
P.S. Make sure you are not inputting your matrix in the output form itself.. the input should be an array as mentioned above.. and in your question.. You have to get it into 4x4 matrix using loops..
  8 件のコメント
Thomas
Thomas 2012 年 4 月 18 日
yeah you need to input the next for loop as well.. how far is your code right now..
Thomas
Thomas 2012 年 4 月 18 日
let me give you some pseudo code... to define the logic
input array; (1x16)
start first row (i) (for loop)
place first element of input array into first row (i) of new matrix (for loop j)
increment your row (i) place the next four alphabets
and do so till you get all your elements in the new matrix..

サインインしてコメントする。


Samuel Awuah Botwe
Samuel Awuah Botwe 2012 年 4 月 18 日
AM STILL FIGURING OUT WHAT AM MISSING IN THE CODE WITH THE GREAT HELP GIVEN ME.SEAN's SOLUTION WORKED RIGHT BUT I GUESS IT HASNT GOT THE FOR LOOP..........AM SOO THANKFULL FOR ALL YOUR EFFORT......I CANT WAIT TO GET IT RIGHT BEFORE I LEAVE FOR LECTURES IN 20 MIN TIME SINCE I NEED TO PRESENT IT TODAY
  1 件のコメント
Jan
Jan 2012 年 4 月 19 日
Please note, that writing uppercase means shouting.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by