how to save filename from string

8 ビュー (過去 30 日間)
Leojik Kannathara
Leojik Kannathara 2019 年 2 月 21 日
コメント済み: Leojik Kannathara 2019 年 2 月 21 日
Hi,
If I can same a string in a variable, is it possible to save a file name with this variable string, such that each time I run a loop, I can save the file name with a different name ?
The idea is shown below. Please ignore any syntax as I am trying to determine that
num = 'first'
rfwrite(first4portsparam, ' "the string num here ".s4p')
So in next loop I will replace
num = 'second'
rfwrite(first4portsparam, ' "the string num here ".s4p')
so in the end I will have 2 files first.s4p and second.s4p
Thanks !
  2 件のコメント
Akira Agata
Akira Agata 2019 年 2 月 21 日
How about saving files using "prefix + serial number" as a file name, such as a001.s4p, a002.s4p,...?
Leojik Kannathara
Leojik Kannathara 2019 年 2 月 21 日
Hi Akira,
I thought about that, but I am not sure how to get a serial number into a file name, without manually adding it.
I am very new to Matlab and I am pretty sure I am not aware of certain functions that I could maybe possibly use to do this.
I had previously create a variable "i" and had a for loop where i was incremented from 0 to 4.
Bu I have not found a way to save out a file name each time as you mentioned a001, a002 etc each time "i" increments.
So I had to resort to creating 4 instances of the same code in a if else statement looking at different values of "i" and then save files as different names in each section. Example shown below:
i=0;
a=1;
b=2;
x2= ((N/2)+1);
y2= ((N/2)+2);
while i < N/4
n2m = [a x2 b y2]
if (i==0)
% The First 4 ports
%n2m = [1 9 2 10];
z0 = nport.Impedance;
first4port = snp2smp(nport.Parameters,z0,n2m,z0);
first4portsparam = sparameters(first4port,freq,z0)
rfwrite(first4portsparam, 'FirstChannel.s4p')
figure(1)
rfplot(first4portsparam,2,1)
hold on
rfplot(first4portsparam,4,3,'-r')
title('4-Port S-Parameter')
hold off
elseif (i==1)
% The Second 4 ports
%n2m=[3 11 4 12];
z0 = nport.Impedance;
second4port = snp2smp(nport.Parameters,z0,n2m,z0);
second4portsparam = sparameters(second4port,freq,z0)
rfwrite(second4portsparam, 'SecondChannel.s4p')
figure(2)
rfplot(second4portsparam,2,1)
hold on
rfplot(second4portsparam,4,3,'-r')
title('4-Port S-Parameter')
hold off
increment i in the end of the if else statement

サインインしてコメントする。

回答 (1 件)

ES
ES 2019 年 2 月 21 日
% This will save files like 1.s4p, 2.s4p, 3.s4p and so on
for iLoop=1:NumberOfFiles
rfwrite(first4portsparam, [num2str(iLoop),'.s4p']);
end
  1 件のコメント
Leojik Kannathara
Leojik Kannathara 2019 年 2 月 21 日
Thank you. The Answer by ES helped solve my issue. You can ignore my previous reply to Akira. Thanks to both of you guys !

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by