필터 지우기
필터 지우기

String and two variables

조회 수: 2 (최근 30일)
Adrian Pielmeier
Adrian Pielmeier 2018년 6월 22일
편집: Stephen23 2018년 6월 22일
Hello Community,
In an excel File i got the following lines:
T_DCT_PK_WDT_W01B1_RANGE
T_DCT_PK_WDT_W02B1_RANGE
T_DCT_PK_WDT_W03B1_RANGE
T_DCT_PK_WDT_W04B1_RANGE
T_DCT_PK_WDT_W05B1_RANGE
the W..B. goes on and isnt in an right order.
So i would to do something like this but there is an error in my syntax:
str = ( 'T_DCT_PK_WDT_W%B%_RANGE' , i ; a )
I would like to have two variables in the string.
I hope you all understand
Thank you!
  댓글 수: 1
Stephen23
Stephen23 2018년 6월 22일
편집: Stephen23 2018년 6월 22일
"...the W..B. goes on and isnt in an right order."
You could easily sort those char vectors into alpha-numeric order by downloading my FEX submission natsort, which sorts a cell array of char vectors by the characters and the values of any numeric substrings:
>> C = {...
'T_DCT_PK_WDT_W01B1_RANGE'
'T_DCT_PK_WDT_W02B1_RANGE'
'T_DCT_PK_WDT_W03B1_RANGE'
'T_DCT_PK_WDT_W04B1_RANGE'
'T_DCT_PK_WDT_W05B1_RANGE'};
>> C = C(randperm(numel(C))) % random order
C =
'T_DCT_PK_WDT_W01B1_RANGE'
'T_DCT_PK_WDT_W02B1_RANGE'
'T_DCT_PK_WDT_W03B1_RANGE'
'T_DCT_PK_WDT_W04B1_RANGE'
'T_DCT_PK_WDT_W05B1_RANGE'
>> D = natsort(C) % sort into alpha-numeric order
D =
'T_DCT_PK_WDT_W01B1_RANGE'
'T_DCT_PK_WDT_W02B1_RANGE'
'T_DCT_PK_WDT_W03B1_RANGE'
'T_DCT_PK_WDT_W04B1_RANGE'
'T_DCT_PK_WDT_W05B1_RANGE'

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

답변 (1개)

Stephen23
Stephen23 2018년 6월 22일
편집: Stephen23 2018년 6월 22일
sprintf('T_DCT_PK_WDT_W%02dB%d_RANGE',i,a)
For example:
>> sprintf('T_DCT_PK_WDT_W%02dB%d_RANGE',5,1)
ans = T_DCT_PK_WDT_W05B1_RANGE
  댓글 수: 3
Stephen23
Stephen23 2018년 6월 22일
"And how do i now search for an specific number?"
Your question does not mention that you want to "search" for a specific number. What does this mean? What is the "number" that you want to search for, and where do you want to search for it?
This line of code hints that you apparently want to match a particular string:
if(i=5 %%a =2)
If this is the case you could do this by using regexp and str2double to extract the numbers:
>> str = 'T_DCT_PK_WDT_W05B1_RANGE';
>> str2double(regexp(str,'\d+','match'))
ans =
5 1
Adrian Pielmeier
Adrian Pielmeier 2018년 6월 22일
Sry for my bad english.
So i got an Excel file whith lines i posted at first. i want to write many if cases for each line in the excel so for example for the line with
T_DCT_PK_WDT_W01B1_RANGE
i want to give back a specefic funktion
i would like to use the variables i and a like you said in my if clause to ask if a=5 and i = 2 the do function
I hope u understand what i mean
Thx!

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

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by