How can I change the dimension of a global variable?

I want to define a global variable:
global v
v=[1 2]
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 can I change the dimension of v? In the data store memory?

7 件のコメント

James Tursa
James Tursa 2014 年 6 月 23 日
Is this in Simulink?
alessandro
alessandro 2014 年 6 月 23 日
Yes, in Simulink
alessandro
alessandro 2014 年 6 月 23 日
Do you know how can I solve it?
José-Luis
José-Luis 2014 年 6 月 23 日
Alessandro, if you want better answers, I would suggest you provide better feedback to the people that are trying to help you, instead of basically asking the same question again.
alessandro
alessandro 2014 年 6 月 23 日
Sorry but I have to complete this work today and I'm looking for any help
José-Luis
José-Luis 2014 年 6 月 23 日
編集済み: José-Luis 2014 年 6 月 23 日
Also, you would make it easier for people to help you if you:
  1. Provide more details
  2. Give a minimum working example reproducing the problem you face. Often, by doing that, you will find the answer yourself.
  3. Provide feedback to the people that try to help you.
What is the data store memory? Have you tried the debugger?
alessandro
alessandro 2014 年 6 月 23 日
編集済み: alessandro 2014 年 6 月 23 日
ok, I try to explain with more details. I have to simulate an inverter modulation in simulink. In the image I show which blocks I've used. Inside the Matlab function there is the code. In this code I've to define a global variable, so I used a Data Store Memory(Help Matlab) like in the second image. In the code I just define a funcion like:
global v
v=[1 2]
but didn't work. 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. So I want to change the dimension of the global variable.

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

回答 (1 件)

Star Strider
Star Strider 2014 年 6 月 23 日

1 投票

I cannot reproduce the error in R2014a. It works even if I assign v before I declare it as a global. However this:
v = pi
global v
v = [1 2]
throws this warning:
Warning: The value of local variables may have been changed to match the globals. Future versions of MATLAB will
require that you declare a variable to be global before you use that variable.
What version are you using?

1 件のコメント

alessandro
alessandro 2014 年 6 月 23 日
編集済み: alessandro 2014 年 6 月 23 日
Ah, I'm using the R2012a

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

質問済み:

2014 年 6 月 23 日

編集済み:

2014 年 6 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by