필터 지우기
필터 지우기

How to embed (insert) variable's that old strings or integers into line of code (%d?)

조회 수: 1 (최근 30일)
לק"י
Hi guys,
I want to use variable's content (like v='name' or b=2.34) to be part of the code it's kind of like %d but as far as I understood it is not quiet like it. i'll explain:
Lets assume I want the code to automatically save figures or run for different inputs and want it to be done with replacing specific regions of the code with the different names of files ot inputs like this:
name='name_I_want' %name I want
b=231 %number I want
xnm=PA 'insert_name/integer_here' dirf(:,1);
ynm=PA 'insert_name/integer_here' dirf(:,2);
figure(1)
scatter(xnm,ynm, 1, 'filled');
title(' 'insert_name/integer_here' cell 2, XY scatter whole cell')
xlabel('nm')
ylabel('nm')
The lines i'm interested to insert\embed the new name\number are:
xnm=PA'insert_name/integer_here'dirf(:,1);
ynm=PA'insert_name/integer_here'dirf(:,2);
title(''insert_name/integer_here'cell 2, XY scatter whole cell')
I tried %d but I saw it only works with sprintf which is a variable of itself and not a way to 'intefere' with the code.
Thanks!
Amit.
  댓글 수: 2
Stephen23
Stephen23 2021년 8월 25일
편집: Stephen23 2021년 8월 26일
Before forcing yourself into writing slow, complex, very inefficient, obfuscated code like that, you should read this:
Numbering variables like that indicates that you are doing something wrong.
Forcing meta-data (e.g. pseudo-indices) into variable names indicates that you are doing something wrong.
Meta-data is data and so should be stored in arrays (not in array names), which will make accessing your (meta-)data much simpler and more efficient. For the data that you have shown, a table might be a suitable array type:
Amit Ifrach
Amit Ifrach 2021년 10월 4일
לק"י
Hi, sorry for the late response, but thanks!

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by