필터 지우기
필터 지우기

If then with strings

조회 수: 1 (최근 30일)
Ubu
Ubu 2012년 3월 2일
Dear all,
a very very simple question on strings and if-then loops.
I loaded an xls file - 384X2 double - which only contains numbers. Let's call it B. I'm simply looking for matching numbers (n) in column 2 and replacing the correspondent value (m) in the correspondent cell in column 1. Replacing numbers with numbers, it works easily:
given n = 5 and m = 7
for i 1:384
if B(i,2) == 5
B(i,1) = 7
end
end
Now the question: what if I want to substitute the values in column 1 with a string - like "bob" or "whatever"? How would the loop look like?
for i 1:384
if B(i,2) == 5
B(i,1) = ???
end
end
Any help is highly appreciated.
Best,
Udiubu

채택된 답변

the cyclist
the cyclist 2012년 3월 2일
To mix strings and numerics in one array, you need to use "cell arrays". Here's a video introduction:
  댓글 수: 1
Ubu
Ubu 2012년 3월 5일
Thanks to both of you!

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 3월 2일
Numeric arrays cannot contain strings. The only kind of arrays that can contain a mix of strings and numbers are cell arrays.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by