store repetitive data results

조회 수: 1 (최근 30일)
Pavel
Pavel 2013년 6월 1일
I can't really explain what i want to do, but i will try my best. I have an repetitive form(for) that for every input value it returns an answer after doing a set of operations. What i want is to store every answer into an string that at the ending of all calculations contains all the answers. Sorry but i'm kind new to MATLAB so please be gentle with me. Thanks.
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2013년 6월 1일
Give an example?
Pavel
Pavel 2013년 6월 2일
if true
for thet=0:5:180;
a=1;
b=0;
c=-5*r^2+2*r^2*sind(thet)*sind(thet)+2*r^2*((4-5*sind(thet)*sind(thet)+sind(thet)*sind(thet)*sind(thet)*sind(thet))^(1/2));
d=[a b c];
e=roots(d);
out=e(e>0)
end
i want every out answer stored into an string.

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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 6월 2일
편집: Andrei Bobrov 2013년 6월 2일
r = 100;
th = 0:5:180;
c = -5*r^2+2*r^2*sind(thet).^2+2*r^2*((4-5*sind(th).^2+sind(th).^4).^(1/2));
x = cell(numel(th),1);
for jj = 1:numel(th)
rt = roots([1 0 c(jj)]);
x{jj} = rt(rt>0);
end
  댓글 수: 1
Pavel
Pavel 2013년 6월 3일
Thank you very much

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

추가 답변 (2개)

Image Analyst
Image Analyst 2013년 6월 1일
Like this?
cellArrayOfStrings = cell(numberOfRuns, 1);
for k = 1 : numberOfRuns
cellArrayOfStrings{k} = SomeFunctionThatReturnsAString(k)
end
SomeFunctionThatReturnsAString() would be some function you write that returns some output argument as a string.

Pavel
Pavel 2013년 6월 2일
편집: Pavel 2013년 6월 2일
clc
r=100;
x=cell(90,1);
for k=1:90;
for thet=0:5:180; %unghiul elementului conduc?tor
a=1;
b=0;
c=-5*r^2+2*r^2*sind(thet).^2+2*r^2*((4-5*sind(thet).^2+sind(thet).^4)^(1/2));
d=[a b c];
v=0:5:180;
e=roots(d);
out=e(e>0);
end
x{k}=out(k)
end
i get the following error when i execute the code: "Attempted to access out(2); index out of bounds because numel(out)=1."

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by