Can I create multiple workspace with variables with the same name?

7 Ansichten (letzte 30 Tage)
Alejandro Caceres
Alejandro Caceres am 2 Mai 2019
Kommentiert: Jan am 16 Aug. 2020
I need to create differents variables to do some activities but normally the variables are named with the same name, can I have more than one workspaces?
  2 Kommentare
KSSV
KSSV am 2 Mai 2019
Why so? Can you give example?
Stephen23
Stephen23 am 2 Mai 2019
Bearbeitet: Stephen23 am 2 Mai 2019
"can I have more than one workspaces?"
Of course: every function instance has its own workspace:
Note that writing code where the variables' names are significant indicates weakness in the code design: variable names should not matter.
For your (totally unexplained task) you are probably much better off using functions, loops or code vectorization. Are you using scripts? If so, you really need to use functions:

Melden Sie sich an, um zu kommentieren.

Antworten (1)

s mohammad hosien abedy nejad
Bearbeitet: Jan am 16 Aug. 2020
you can use structure also.
s(1).var1 = ....
s(2).var1 = ....
s(3).var1 = ....
for use s in other functions declare it as global
  1 Kommentar
Jan
Jan am 16 Aug. 2020
Global variables cause more problems, than they solve. But a struct is a good solution here.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Variables finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by