Vous êtes sur la page 1sur 3

4/11/13

How to save, for loop - MATLAB Answers - MATLAB Central


Search: Answers Rahul Bajaj Create Community Profile Log Out

File Exchange

Answ ers

New sgroup

Link Exchange

Blogs

Trendy

Cody

Contest

MathWorks.com

How to save, for loop


Asked by Hello kity on 14 Dec 2012 Latest activity Commented on by Hello kity on 14 Dec 2012 Accepted Answ er by Pedro Villena

Example: for i=1:n X=DATA1(i,1); Y=DATA2{1,i}; Z=X-Y; end what I want is that it saves the data to Z, summing them, so, for i=1 , Z=[1 2 3 4 5], for i=2 Z becomes Z=[1 2 3 4 5 6 7] etc. so i need to do something with Z but dont know what. currently it only shows the result of the last i.

2 Comments
Show all comments Image Analyst on 14 Dec 2012 Link

Direct link to this comment: http://www.mathworks.in/matlabcentral/answers/56588#comment_117220


Flag Include the reason for your flag below : Your message w ill be publicly visible.

Save Cancel

Do you really have X as a numerical array (double, etc.) and Y as a cell array???
Hello kity on 14 Dec 2012 Link

Direct link to this comment: http://www.mathworks.in/matlabcentral/answers/56588#comment_117226


Flag Include the reason for your flag below : Your message w ill be publicly visible.

Save Cancel

yes x= column full of values (nummerical array) and Y cells , with each cell with diff lengths

0 votes
Flag

A flag is a request to an editor to review and potentially close or delete content on MATLAB Answers. Include the reason for your flag below.
Not appropriate for MATLAB Answ ers More

Inappropriate flags an invalid question. These questions lack any of the following: Detail for ensuring a proper response Sufficient work or thought on the part of the requester (do-it-for-me request) Usefulness to the community
Spam More

This question is spam.


Unclear More

Unclear flags a question requiring more information. These questions are illogical, lack detail, or may not be a question. Unclear questions can be reopened within 10 days of closure. Thereafter, unclear questions become permanently deleted.
Provide additional information about your flag below Your message w ill be publicly visible.

www.mathworks.in/matlabcentral/answers/56588-how-to-save-for-loop

1/3

4/11/13

How to save, for loop - MATLAB Answers - MATLAB Central

Save Cancel

Tags
cell2mat

Products
MATLAB

1 Answer
Answ er by Pedro Villena on 14 Dec 2012 Edited by Pedro Villena on 14 Dec 2012 Accepted answ er

f o ri = 1 : n , X=D A T A 1 ( i , 1 ) ;% %D A T A 1i sa na r r a y Y=D A T A 2 { i , 1 } ;% %D A T A 2i sac e l l Z ( i , : )=X Y ; e n d s a v eZ or Z=D A T A 1+c e l l 2 m a t ( D A T A 2 ) ; s a v eZ

1 Comment
Show all comments Hello kity on 14 Dec 2012 Link

Direct link to this comment: http://www.mathworks.in/matlabcentral/answers/56588#comment_117214


Flag Include the reason for your flag below : Your message w ill be publicly visible.

Save Cancel

the first one works if both X and Y are matrix ( ()) but if Y is cell array {} then it gives trouble. Somehow I need to convert Y to matrix then put it in the equation. I look into the second tip thank you

0 votes
Flag Include the reason for your flag below : Your message w ill be publicly visible.

Save Cancel Link

Direct link to this answer: http://www.mathworks.in/matlabcentral/answers/56588#answer_68515 Create a community profile to answer or comment on this question.
Contact us

www.mathworks.in/matlabcentral/answers/56588-how-to-save-for-loop

2/3

4/11/13
1994-2013 The MathWorks, Inc.

How to save, for loop - MATLAB Answers - MATLAB Central


Site Help Featured MathWorks.com Topics: Patents Trademarks Support Privacy Policy Preventing Piracy Webinars Terms of Use Newsletters MATLAB Trials Careers

New Products

Documentation

Training

www.mathworks.in/matlabcentral/answers/56588-how-to-save-for-loop

3/3

Vous aimerez peut-être aussi