Anyone know how to input a string into a for loop?

I am trying to loop a vector of strings into a given function, but everytime it goes through the for loop, it is viewed as a whole bunch of ascii character values. Anyone have any ideas how to keep it as a string?
temp1 = ['1991/05/19 13:00:00','1991/07/19 13:00:00']
[a1 a2] = size(temp1)
for i = 1:a2
temp2 = temp1(i)
[temp3(i) temp4(i)] = SolarAzEl(temp2,30,60,0.15)
end
%This is the input type for the function [Az El] = SolarAzEl('1991/05/19 13:00:00',50,10,0)

답변 (1개)

Matt Fig
Matt Fig 2012년 9월 28일
편집: Matt Fig 2012년 9월 28일

0 개 추천

You should use a cell array instead of a character array:
temp1 = {'1991/05/19 13:00:00','1991/07/19 13:00:00'};
temp1{1} % Notice the use of {} instead of () or []
temp1{2}

댓글 수: 3

Franco replied:
"I still have the problem of the size function counting the number of ascii values rather than 2 strings. In other words, a2 is something like 30 rather than 2"
You did not do what I did then:
>> temp1 = {'1991/05/19 13:00:00','1991/07/19 13:00:00'};
>> [a1 a2] = size(temp1)
a1 =
1
a2 =
2
Franco you are using [ ] rather then { }

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

카테고리

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

질문:

2012년 9월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by