# instructor gave us set(gca,'X​Tick',1:le​ngth(numVa​l)); how do i use this for setting color to inputs?

조회 수: 1 (최근 30일)
Richard 2014년 12월 5일
답변: matt dash 2014년 12월 5일
set(gca,'XTick',1:length(numVal)); set(gca,'XTickLabel',numVal(1,:));
the task is to set the inputs we put in to the line color in plotting, I imagine this set has something to do with it, can anyone explain this? Having a hard time setting the inputs as the color of my lines in plotting.
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
dpb 2014년 12월 5일
The above set has nothing whatsoever to do with colors so it's irrelevant to the question subject. All this does is set the number of tick marks and their labels to the values in the first row of the array numVal. (BTW, the use of length here isn't robust coding;
length(X)=max(size(X)); % by definition
so if the array were to happen to have more rows than columns, there would be a mismatch and an error raised. If, numVal is a vector, then the second size value is 1 so it works, but then the subscripting expression (1,:) is totally superfluous).

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

### 채택된 답변

matt dash 2014년 12월 5일
The [ ] operator in matlab concatenates things. For example [1 2 3] concatenates 3 numbers to make a vector. Similarly ['r','^-'] results in 'r^-'. So if the user inputs a one-character color, you can use it like this: plot(x,y,[color,'^-']). Note that there are no quotes around color because it is the name of a variable that contains a string, NOT a string itself.

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

### 추가 답변 (1개)

Richard 2014년 12월 5일
Okay the task states that we should make inputs for the color of line 1, line 2 ect. But you have to have an input statement to put in the color. For example Color1=input('enter the color of line 1: '); Say you are given x and y arrays, how do you plot x and y with that color from the input? Plot(x, y, 'color1^-') doesn't work. And thanks for telling me what that set meant. Appreciate you helping.

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

### 카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by