how to use name of char file to call file of same name in matlab

1 view (last 30 days)
if true
load Full-load1.mat;
for k=5:1:7
A=upper(char(k+92))
nme=sprintf('%d_%c',k,A)
nme1=sprintf('Data1_AI_0816_%s_LEM_single_mo',nme);
y=(nme1);
subplot(5,2,1)
plot(y)
grid on, box on, xlim([0 500]), ylim([-65 65])
xlabel('Time (Samples)','FontSize',14)
ylabel('Current (A)','FontSize',14)
get(gca,'fontname') % shows you what you are using.
set(gca,'fontname','times','FontSize',14) % Set it to times
hold on
subplot(5,2,2)
plot(y)
hil=hilbert(y);
grid on, box on, xlim([0 60000]), ylim([0 65])
xlabel('Time (Samples)','FontSize',14)
ylabel('Current (A)','FontSize',14)
get(gca,'fontname') % shows you what you are using.
set(gca,'fontname','times','FontSize',14) % Set it to times
hold on
plot(abs(hil))
end
end
Hello Guys;
I am trying to call a .double file from workspace using sprintf commands as shown in attached pic. The address is generated successfully but how to use its name only to call that file in workspace. it is not working because generated address is character.

Accepted Answer

Stephen23
Stephen23 on 6 May 2018
Moved: Voss on 14 Dec 2023
Oh, this would by so easy if you load-ed that .mat file into a structure, like this:
S = load('Full-load1.mat')
Then you could easily access its fields, eg. using fieldnames.
What you are trying to do is to dynamically access variable names which were spammed into the workspace by load. Dynamically accessing variable names makes code slow, complex, buggy, and hard to debug. Read this to know why:
Please upload your .mat file by clicking the paperclip button, and we will show you how to do this in a much simpler way.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!