Hello everyone,
I have let's say : x=' a name' ; and B= [1 2 3],
and I want to create a variable ' a name' = B whiche is [1 2 3], in another word i want to create a variable using the string of another variable (example filename='Hallo' the 'Hallo'= B=[1 2 3],
So, I tried to use [x]=B; but it does not work;

댓글 수: 3

Stephen23
Stephen23 2021년 1월 7일
편집: Stephen23 2021년 1월 7일
Is there a particular reason why you need to magically define variable names?
Usually when beginners ask about this topic it is because of this:
Given that your own example ' a name' is an invalid variable name, is there any particular reason why you want to force yourself into writing slow, complex, fragile, obfuscated code that is difficult to debug?
Ayman Mounir
Ayman Mounir 2021년 1월 7일
actually, I read many csv data and concantae them in one matlab table then i have to save as the specfic name :
for example: dir()
all_table=[] % concatenate all csv files
for i=1:numel(files);
R= readtable((files(i).name));
all_table=[all_table;R];
save (all_table, 'standard_name') % mast save as mat file because i exceeded 2^20 ( the limit of exporting an excel file) but this command does not include an option to save the file with desired name.
:D
Stephen23
Stephen23 2021년 1월 7일
편집: Stephen23 2021년 1월 7일
@Ayman Mounir: your save usage makes no sense.
The first input argument of save must be a filename, so why are you providing a table as the first input?
The second input is usually the name of the variable to be saved, it is not clear what you expect the character vector 'standard_name' to achieve. I recommend that you read the save documentation, it explains how to use save.
In any case, magically defing variable names is unlikely to be a suitable solution to ... whatever you problem might be.

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

답변 (2개)

Catalytic
Catalytic 2021년 1월 7일

0 개 추천

s.(x)=B
Stephen23
Stephen23 2021년 1월 7일
편집: Stephen23 2021년 1월 7일

0 개 추천

The MATLAB approach:
N = numel(files);
C = cell(1,N);
for k = 1:N
F = fullfile(files(k).folder,files(k).name);
C{k} = readtable(F);
end
dataname = vertcat(C{:});
save('some_file_name.mat', 'dataname')

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2020b

질문:

2021년 1월 7일

편집:

2021년 1월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by