MATLAB: [1 1 2 2 3 3] –> [11 22 33]

arraysfor loophomeworkMATLAB

Hi, how can I make from [1 1 2 2 3 3], [11 22 33]? I thought we need to do this with a for loop. Thanks

Best Answer

Start with this outline:
x = your initial variable of values
[m,n] = size(x);
result = zeros(___,___); % <-- you fill in the blanks with appropriate values based on m and/or n
for k=1:___ % <-- you fill in the blank with the appropriate range based on m and/or n
result(k) = ______; % <-- you fill in the expression
end
The indexing will be some expression involving m and/or n. The expression will be some expression involving two values from x (with the appropriate indexing). Fill in the blanks as best you can, and then when you have problems post follow-up comments showing your code, telling us what errors you are getting, and asking specific questions about it.