How do I load a variable from another file?

I'm in the process of making a game where at the end it will compare your score to the high scores. I had to create separate files called highScores.m it contains:
global highScores
highScores = [0,0,0,0,0];
and highScoreNames.m :
global highScoreNames
highScoreNames = ['none';'none';'none';'none';'none'];
I am trying to load these variables using:
load('highScores.m');
load('highScoreNames.m');
but I get an error saying:
Error using load
Number of columns on line 2 of ASCII file highScores.m must be the same as previous lines.
Thanks!

回答 (1 件)

KSSV
KSSV 2018 年 3 月 12 日

0 投票

highScores = [0,0,0,0,0];
highScoreNames = ['none';'none';'none';'none';'none'];
save GameScores.mat
You load this .mat file..where you want the scores......don't use global......you can save data in matlab in various file formats.....have a look on save.

カテゴリ

ヘルプ センター および File ExchangeEnvironment and Settings についてさらに検索

タグ

質問済み:

2018 年 3 月 12 日

回答済み:

2018 年 3 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by