unknown number of elements
조회 수: 1 (최근 30일)
이전 댓글 표시
I'm a beginner ...... I have unknown number of stream orders (st.order).... For each st.order i have unknown number of streams (st.number(st.order)) each one wit a different length.... I wanna get the number of the streams and the sum of their lengths for each stream order in a structure or in 3 vectors (stream order, the number of the streams and the sum of their lengths).....i tried this but it doesn't work.
if true
[fn pn] = uigetfile('*.*','pick an image');
complete = strcat(pn,fn);
I = imread(complete);
imshow(I,[])
hold on
xy = [];
n = 0;
but = 1;
while but == 1
[xi,yi,but] = ginput(1);
plot(xi,yi,'rx','LineWidth',2)
n = n+1;
xy(:,n) = [xi;yi];
end
plot(xy(1,:),xy(2,:),'m-','LineWidth',2);
scale = sum(sqrt(diff(xy(1,:)).^2 + diff(xy(2,:)).^2));
st.order = input('stream order=');
for st.order = 1:??;
st.number(st.order) = 0;
st.length(st.order) = 0;
for m='y':'n';
xy = [];
n = 0;
but = 1;
while but == 1
[xi,yi,but] = ginput(1);
plot(xi,yi,'rx','LineWidth',2)
n = n+1;
xy(:,n) = [xi;yi];
end
plot(xy(1,:),xy(2,:),'m-','LineWidth',2);
l = (sum(sqrt(diff(xy(1,:)).^2 + diff(xy(2,:)).^2)))/scale;
st.number(st.order) = st.number(st.order)+1;
st.length(st.order) = st.length(st.order)+l;
m=input('Do you want to continue, y/n [y]:','s');
if m=='n'
break
end
end
st.order = st.order+1
end
any one could help??
댓글 수: 2
Ingrid
2015년 5월 11일
it is not really clear what you want to obtain. Also, if you use a for-loop there is no need to increment at the end as this is done automatically (this would be required if you would be using a for-loop also you are assiging the st.order and then re-assign it in your code maybe you are trying to do this?
st.order = input('stream order=');
for ii = 1:st.order
st.number(ii) = 0;
st.length(ii) = 0;
...
end
but again, it is not clear what you are trying to achieve, and most of all, if the structure you design is the appriorate way to go (in your tag you placed matrices but you do not put your data in a matrix but in a structure)
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

