Assigning a variable according to file name..

I want the variable to be changed according to the file name.. Like;
Simulation File 1 Track 2
Simulation File 1 Track 4
Simulation File 1 Track 6
.
.
.
I want those track values assigned in a formula and get the value as the loop continues taking the track value like 2-4-6. Thank you all

3 Kommentare

Stephen23
Stephen23 am 12 Okt. 2020
"I want the variable to be changed according to the file name.."
That would be about the worst approach to importing data.
Putting meta-data into variable names is a sign that you are doing something wrong.
Meta-data is data and belongs in variables, not forced into variable names. Badly designed data (with meta-data in the variable names) makes accessing the data slow, complex, inefficient, obfuscated, buggy, and difficult to debug:
The MATLAB documentation shows examples which use simple and efficient indexing to store imported file data:
Is there a particular reason why you cannot use simple, neat, efficient indexing and a cell array? (or a table, struct, etc)
FG
FG am 12 Okt. 2020
Stephen, I appriciate your helps indeed.. That's because I am absolutely rookie about coding. I almost know nothing I can say.. Process just came in a way like this and I have to get that going : (
FG
FG am 13 Okt. 2020
OK.. I took Stephen's advice and decided to do this in a different way.. From 1 to 480, I want to multiply
1st row with 0
2nd with 10
3rd with 2
4th with 4
5th with 6
6th with 8
and then
7th with 0 again
8th with 10 again.. son on ! Every 6 turns it should repeat this till 1 to 480

Melden Sie sich an, um zu kommentieren.

Antworten (2)

KSSV
KSSV am 12 Okt. 2020

0 Stimmen

You need not to change the variable as based on filename..you can initialize an array/ matrix and save the variables into this.
Option 1: If size is always same
n = 10 ; % number of files
iwant = zeros(3,3,n) ; %
for i = 1:n
iwant(:,:,i) = rand(3) ; % save data here
end
Otion 2: If size varies
n = 10 ;
iwant = cell(n,1) ;
for i = 1:n
m = randperm(100,1) ;
iwant{i} = rand(m) ;
end
Sudhakar Shinde
Sudhakar Shinde am 12 Okt. 2020

0 Stimmen

Example:
Track = 2;
File = 2;
Filename = {};
for j=1:(File)
for i = 1:(Track)
Filename{end+1} = ['SimulationFile' num2str(j) , ' Track' num2str(i)];
end
end

Kategorien

Produkte

Version

R2020a

Gefragt:

FG
am 12 Okt. 2020

Kommentiert:

FG
am 13 Okt. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by