Help me I am unable to input array

조회 수: 2 (최근 30일)
Ishmum Monjur Nilock
Ishmum Monjur Nilock 2020년 7월 29일
댓글: Ishmum Monjur Nilock 2020년 7월 29일
Hello everyone, when I try to input numbers as array like [1 2 3 4] and want to print the output as array that I gave as input, it is saying that Unable to perform assignment because the indices on the left side are not compatible with the size of the right side. Please help me to solve the problem. The code is as follows:
for i=1:4
x(i)=input('Enter elements of x=');
end
disp(x);

채택된 답변

Stephan
Stephan 2020년 7월 29일
편집: Stephan 2020년 7월 29일
They way you coded it needs to enter the single values one after each other:
Enter elements of x=1
Enter elements of x=2
Enter elements of x=3
Enter elements of x=4
1 2 3 4
maybe try:
x(1,:)=input('Enter elements of x=');
disp(x)
Enter elements of x=[1 2 3 4]
1 2 3 4
  댓글 수: 1
Ishmum Monjur Nilock
Ishmum Monjur Nilock 2020년 7월 29일
Actually I didn't realize the fact in this way. But thanks a lot!!!!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by