필터 지우기
필터 지우기

how to creating matrix h 4x2 with some rules

조회 수: 2 (최근 30일)
Noru
Noru 2013년 3월 21일
I have some trouble when creating matrix 4x2 with rules like below. the first column are integer and the other column are random number. I already create the syntax below.
for ii = 1:8,
nilai = mod(ii,2);
if nilai == 0
x(ii) = 0.95 + (1.05-0.95)*x(ii);
elseif nilai ~= 0
x(ii) = round(3 + (30-3)*x(ii));
elseif nilai ~= 0
x(ii) = 0.01 + (0.055-0.01)*x(ii);
else
x(ii) = 1.0 + (1.15-1.0)*x(ii);
end
end
x = reshape(x,4,2)';
but the result are
??? Error using ==> reshape
To RESHAPE the number of elements must not change.
anyone can help me with this problem..? any solutions are very welcome..
thank you.

채택된 답변

the cyclist
the cyclist 2013년 3월 21일
What is the shape of x before you start? It seems that it is probably not an 8-element array, so the reshape fails.
  댓글 수: 3
the cyclist
the cyclist 2013년 3월 21일
You did not answer my question. What is the shape of x BEFORE this loop?
As you can see from Image Analyst's answer, there is no problem if x is 1x8 before your loop.
Noru
Noru 2013년 3월 27일
i think i ask the wrong question..
thanks for your help.. :))

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

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 3월 21일
I got a different error message due to x not being predefined and your new x(ii) depends on your old x(ii). When I predefined x, it ran with no errors:
x = zeros(1, 8);
for ii = 1:8
nilai = mod(ii,2);
if nilai == 0
x(ii) = 0.95 + (1.05-0.95)*x(ii);
elseif nilai ~= 0
x(ii) = round(3 + (30-3)*x(ii));
elseif nilai ~= 0
x(ii) = 0.01 + (0.055-0.01)*x(ii);
else
x(ii) = 1.0 + (1.15-1.0)*x(ii);
end
end
x = reshape(x,4,2)'
In the command window:
x =
3 0.95 3 0.95
3 0.95 3 0.95
  댓글 수: 2
Noru
Noru 2013년 3월 21일
now i already done create a matrix like you do, but i want to make the value of the 3rd column like 2nd and 4th(non integer number) like below
x =
8 0.67 0.32 0.76
14 0.49 0.21 0.53
do you have any solution..?
Image Analyst
Image Analyst 2013년 3월 21일
% make the value of the 3rd column like 2nd
x(:,3) = x(:,2);
% make the value of the 3rd column like 4th
x(:,3) = x(:,4);

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

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by