How declare a global vector

조회 수: 39 (최근 30일)
alessandro
alessandro 2014년 6월 23일
답변: Image Analyst 2014년 6월 24일
I want to declare a global variable V1, dimensions [2 x 1]:
global V1
Vll=[floor(Vrefg); floor(Vrefh)];
V1=Vll;
But I have this error: Size mismatch (size [1 x 1] ~= size [2 x 1]). The size to the left is the size of the left-hand side of the assignment. How I can change the dimensions of V1?
  댓글 수: 1
José-Luis
José-Luis 2014년 6월 23일
편집: José-Luis 2014년 6월 23일
The use of globals is discouraged.
Without a minimum working example, telling you how to change V1 is an exercise in wild conjectures, since we don't know what you are trying to achieve. Those tend to be not that much fun.
Furthermore, this sounds like the king of problem that is a good fit for the debugger:
dbstop if error %then run your program

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

답변 (2개)

David Sanchez
David Sanchez 2014년 6월 23일
The fact of being a global variables has nothing to do with its dimension. The following is perfectly valid:
global v
v=[1 2]
Make sure that your line:
Vll=[floor(Vrefg); floor(Vrefh)];
is well defined and its elements are scalars.
  댓글 수: 3
alessandro
alessandro 2014년 6월 23일
Can I change the dimension in the Data store memory?
David Sanchez
David Sanchez 2014년 6월 24일
Do you mean that when you type
global V1
V1=[1 2]
in the command window, you get an error?
Try
clear global
before, that would delete any other previous declaration of global variables. If you get the error again, it has to be something related to your system.

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


Image Analyst
Image Analyst 2014년 6월 24일
Looks like you might have changed your question. If you have
global V1
Vll=[floor(Vrefg); floor(Vrefh)];
V1=Vll;
Then Vrefg and Vrefh must both be scalars or have the same number of columns if they are arrays. What is the value of those two variables?

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by