필터 지우기
필터 지우기

Add phrase to string if condition is true

조회 수: 3 (최근 30일)
Christopher Schoß
Christopher Schoß 2022년 5월 5일
편집: Walter Roberson 2022년 5월 6일
Hey!
I have a probleming coding a string, here is my current code:
int i = 4;
String[] testString = new String[i];
for (int j = 0; j < i; j++)
{
testString[j] = String.valueOf("test"+(j+1));
}
model.set("input", testString);
which is resulting in:
model.set("input", "test1", "test2", "test3");
___________________
Now I want to extend the code and print just an additional testX if a corresponding condition is true and every testX has a different condition with previous defined parameters like:
condition for test1: parameter1<parameter2
condition for test2: parameter2<parameter3
condition for test3: parameter4>parameter3
For example if condition 2 is not true the result should be:
model.set("input", "test1", "test3");
___________________
I would appreciate any help here!!
Thank you!

채택된 답변

Mitch Lautigar
Mitch Lautigar 2022년 5월 5일
int i = 4;
String[] testString = new String[i];
for (int j = 0; j < i; j++)
{
testString[j] = String.valueOf("test"+(j+1));
}
model.set("input", testString);
This code is either C/C++ and I have not seen this syntax used in programming MATLAB. However, in an attempt to help you, the logic i'd suggest is to make sure test_string is actually saving as a string array. C/C++ don't tend to like a variable changing memory size during the code running. See if that helps, and if it doesn't, comment again and i'll see what I can do to further help you.
  댓글 수: 6
Christopher Schoß
Christopher Schoß 2022년 5월 6일
I think you mean add:
testString = cellstr(output_str);
model.set("input",testString{:});
?
Thank you!
Christopher Schoß
Christopher Schoß 2022년 5월 6일
Now I got it:
output = strjoin(output_str,'","');
Thank you :)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by