Loop for plotting two columns again and again in a 205x10 cell arrray
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
Hello, I have a .mat file in which there are 10 columns and I want to obtain a plot for two columns each with X-axis being the first column and Y-axis being the second column and repeat the same for columns-3,4. This way I will have 5 different figures. I need all the plots separately. Can anyone guide me how to achieve this? I tried creating a matrix first and then using a for loop, but it didn't turn out good. I'm attaching the .mat file.
Accepted Answer
madhan ravi
on 29 Aug 2018
Edited: madhan ravi
on 29 Aug 2018
clear all
Datas = load('194tp.mat')
x1 =Datas.c(:,1)
y1 = Datas.c(:,2)
x2 =Datas.c(:,3)
y2 = Datas.c(:,4)
x3 =Datas.c(:,5)
y3 = Datas.c(:,6)
x4 =Datas.c(:,7)
y4 = Datas.c(:,8)
x5 =Datas.c(:,9)
y5 = Datas.c(:,10)
for i =2 : length(x1)
a{i}=x1{i}
b{i}=y1{i}
c{i}=x2{i}
d{i}=y2{i}
e{i}=x3{i}
f{i}=y3{i}
g{i}=x4{i}
h{i}=y4{i}
j{i}=x5{i}
k{i}=y5{i}
end
x1=cell2mat(a)
y1=cell2mat(b)
x2=cell2mat(c)
y2=cell2mat(d)
x3=cell2mat(e)
y3=cell2mat(f)
x4=cell2mat(g)
y4=cell2mat(h)
x5=cell2mat(j)
y5=cell2mat(k)
figure(1)
plot(x1,y1)
figure(2)
plot(x2,y2)
figure(3)
plot(x3,y3)
figure(4)
plot(x4,y4)
figure(5)
plot(x5,y5)
14 Comments
ankit varma
on 29 Aug 2018
I have tried using the following code and it gives the error "Error using plot. Not enough input arguments'.
in=load('194tp.mat')
c=in.c;
n=5
for i=1:2n
x=c(:,i)
y=c(:,i+1)
plot(x,y)
end
madhan ravi
on 29 Aug 2018
yes because there is header in the cell just trying to eliminate it.
ankit varma
on 29 Aug 2018
I apologize for my poor knowledge but where in my code am I going wrong?
madhan ravi
on 29 Aug 2018
give me some time just figuring it out even its new for me
ankit varma
on 29 Aug 2018
Sure! Didn't mean to rush it. please take your time.
madhan ravi
on 29 Aug 2018
check the code now it works
ankit varma
on 29 Aug 2018
I've tried using the modified code shared by you. It's printing the data but not generating the required plots. It's generating only a single plot of the first two columns.
madhan ravi
on 29 Aug 2018
check the code now.
madhan ravi
on 29 Aug 2018
is this what you were looking for?
ankit varma
on 29 Aug 2018
It seems that I don't have the symbolic math toolbox required to use the 'sym' argument. Again, it's printing the data in the command window and not plotting it. Really appreciate your efforts here!
madhan ravi
on 29 Aug 2018
check now
madhan ravi
on 29 Aug 2018
if it is working please accept the answer and give a vote.
ankit varma
on 29 Aug 2018
Madhan, It's working now. The required plots have been generated! thanks a lot for helping me with this!
madhan ravi
on 29 Aug 2018
Edited: madhan ravi
on 29 Aug 2018
My pleasure,my suggestion is install symbolic toolbox it is really useful and easier for many operations
More Answers (0)
Categories
Find more on Graphics in Help Center and File Exchange
Tags
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)