Efficiently Set a Sequence in Matlab: Quick Question Answered

  • Context: MATLAB 
  • Thread starter Thread starter lewdtenant
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary

Discussion Overview

The discussion revolves around setting sequences in MATLAB, specifically how to create an array with specified increments and how to adjust axis tick marks for plots. It includes both a homework-related question and technical clarifications regarding plotting.

Discussion Character

  • Homework-related
  • Technical explanation

Main Points Raised

  • One participant seeks a more efficient way to create an array with 9 increments from 0 to 64, suggesting a brute force method and expressing uncertainty about better alternatives.
  • Another participant suggests using the 'linspace' function as a potential solution.
  • A different participant asks about plotting more points on the x-axis and y-axis, specifically wanting to adjust the tick marks to show increments of 1 instead of larger intervals.
  • One participant proposes using the syntax x = [5:1:20] for both x and y to achieve the desired points, but notes that the tick marks do not reflect this increment.
  • Another participant explains that the tick marks can be adjusted through axis properties or command line commands, providing an example of how to set tick marks and labels explicitly.
  • A later reply expresses gratitude for the clarification provided regarding tick marks.

Areas of Agreement / Disagreement

Participants express varying levels of understanding and approaches to the questions posed, with no consensus reached on the best method for setting sequences or adjusting tick marks.

Contextual Notes

Participants do not fully agree on the most efficient methods, and there are unresolved aspects regarding the best practices for plotting in MATLAB.

lewdtenant
Messages
63
Reaction score
1
Matlab --> quick question

Homework Statement



suppose I want to set a = [0:64] with an output of 9 increments. For the life of me I cannot remember how to do this other than doing it brute force style.


Homework Equations





The Attempt at a Solution



since 64/9=7.11 then, a =[0:7.11:64] gives me 9 increments but I know there's a better way to do this. please help, thanks.
 
Physics news on Phys.org
help linspace
 
yes, thanks
 
is there a way that i can plot more points in the x-axis and the y-axis? instead of going by 5 -10 -15- 20 and go 5 - 6 - 7 - 8 - 9...20 .
 
well, I'm no MATLAB expert, but here goes.

When you specify x and y, making x= [5:1:20] will give you 5, 6, 7, 8... 20. you can do this for y also. then when you plot (x, y) it should give you what you need.

i hope that helps, let me know if i misunderstood your question.
 
if i plot x= [5:1:20] and y= [5:1:20], the axes spacing goes 5,10,15,20, but i would like to make it go 1 by 1. thus showing more points in the plot.

not sure if that is possible, but that´s why I am asking i guess.

thanks for your help btw
 
tko_gx said:
if i plot x= [5:1:20] and y= [5:1:20], the axes spacing goes 5,10,15,20, but i would like to make it go 1 by 1. thus showing more points in the plot.

not sure if that is possible, but that´s why I am asking i guess.

thanks for your help btw

I think you're just referring to the tick marks on the axis. The distribution of tick marks is not related to the number of points plotted on the graph. You can change the tick mark distribution either going to 'axis properties' in the 'edit' menu of the plot, or you can define them from the command line. For example,
Code:
x = -pi:.1:pi;
y = sin(x);
plot(x,y)
set(gca,'XTick',-pi:pi/2:pi)
set(gca,'XTickLabel',{'-pi','-pi/2','0','pi/2','pi'})
defines the tick placement and the labels.
 
thank you very much. that's exactly what i meant to say.
 

Similar threads

Replies
6
Views
4K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
9K
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K