How do I input a variable that contains a previous variable?

The input for my function requires a letter "d" after a variable that I calculate, as shown below. I can't get it to work because I don't know the syntax for the code.
function [S0,S1,S2,S3] = calcStokes(n)
full_name = fullfile('I0R', n);
full_name2 = full_named;
I0value = I0(full_name2,full_name);
disp(I0value)
Above is the code that requires 2 inputs, one with the a name "n" and one with a name "nd"

 채택된 답변

Walter Roberson
Walter Roberson 2015년 7월 26일
full_name = fullfile('I0R', sprintf('%d', n));
full_name2 = [full_name 'd'];
But considering your other postings I suggest you are probably looking for something more like
base = sprintf('%d',n);
full_name = fullfile('IOR', [base '.bmp']);
full_name2 = fullfile('IOR', [base 'd.bmp']);

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2015년 7월 25일
편집: Azzi Abdelmalek 2015년 7월 25일
Define nd as peristent variable. Look at this example
function y=myfcn(n)
persistent nd
if isempty(nd)
nd=0
end
y=2*n+nd
nd=n

댓글 수: 3

Sulaiman Alvi
Sulaiman Alvi 2015년 7월 25일
편집: Sulaiman Alvi 2015년 7월 25일
I'm sorry, I didn't explain myself properly. I want to be able to input 0 as n, and load in two files from the folder: 0 and 0d. This means that 0d is an actual file name.
This is not clear
Edited for clarity.

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

카테고리

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

질문:

2015년 7월 25일

댓글:

2015년 7월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by