# Spliting a line segment into desired length segments (Matlab)

• MATLAB
• mushi
In summary, the speaker is seeking help in splitting major line segments into multiple minor segments of equal length in Matlab. They mention that the 'linspace' function can only control the number of segments, not their lengths, and they want the coordinates for each segment. They provide an example of wanting to divide 3KM, 5KM, and 12KM segments into smaller 2.5KM segments. They ask for any assistance and suggest using the 'linspace' function or the colon operator.
mushi
Hi Guys,

I don't know if I make sense but please try to help me.

I am working in Matlab. I have multiple line segments of different lengths with end point coordinates. I want to split each major segment into multiple minor segments in a way that all segments will have same length. 'linspace' can only control number of segments regardless of their lengths. For me, number of segments are not important, but their lenghts are important (must be equal). I want their coordinates like 'linespace' does. It is not necessary that the full length of all segments will be utilized.

For example:
I have Major segments of:
(1) 3KM (2) 5KM (3) 12KM (with their end points)

I want to get:
I want to divide each major segment into multiple minor segments (say 2.5 KM each) with their coordinates.

Any help will be greatly appreciated.

Mushi

What is a line segment? Can you give an example of your code?

calculate n by dividing the major segment length by the minor length, then use linspace
or
use the colon operator ... 0:2.5:12

## 1. How can I split a line segment into equal length segments in Matlab?

To split a line segment into equal length segments in Matlab, you can use the "linspace" function. This function divides a given interval into a specified number of equally spaced points, which can then be used as the endpoints for your desired segments.

## 2. Can I specify the exact length of each segment when splitting a line in Matlab?

Yes, you can specify the exact length of each segment when splitting a line in Matlab. You can use the "diff" function to calculate the length of your line segment, and then divide that length by the number of desired segments to determine the length of each segment.

## 3. What if I want to split a line segment into segments of different lengths?

If you want to split a line segment into segments of different lengths, you can use the "cumsum" function to create a vector of the desired lengths. Then, you can use the "diff" function to calculate the differences between each element in the vector, which will give you the lengths of each segment.

## 4. How can I visualize the split line segments in Matlab?

You can visualize the split line segments in Matlab by using the "plot" function. After splitting the line segment into desired length segments, you can use the "hold on" command to plot each segment as a separate line.

## 5. Can I split a line segment into a specific number of segments in Matlab?

Yes, you can split a line segment into a specific number of segments in Matlab. You can use the "linspace" function to create a vector of equally spaced points, and then use the "diff" function to determine the length of each segment. Alternatively, you can use the "cumsum" function to specify the exact lengths of each segment.

• Precalculus Mathematics Homework Help
Replies
17
Views
1K
• MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
537
• Special and General Relativity
Replies
40
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
• MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
• Mechanical Engineering
Replies
20
Views
1K
• General Math
Replies
2
Views
1K
• MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K