Possible solution to this problem

조회 수: 1 (최근 30일)
Ghenji
Ghenji 2018년 4월 16일
편집: Ghenji 2018년 4월 18일
I have got variable A as,
A = {'char1', 'char2'}; %could be char3, char4, char5....so on
There would always be two elements in variable A. Now I have got list of such character elements from which would further give me value of four more variables.
char1 = {x1 = 0, x2 = 2.3, y1 = 2.3, y2 = 2.3};
char2 = {x1 = 0, x2 = 6.5, y1 = 6.5, y2 = 6.5};
char3 = {x1 = 0, x2 = 3.4, y1 = 3.4, y2 = 3.4};
char4 = {x1 = 0, x2 = 8.2, y1 = 7.5, y2 = 8.2};
char5 = {x1 = 0, x2 = 5.5, y1 = 6.5, y2 = 5.5};
now main condition where i want to use this values -
line(handles.axes1, [x1;x2], [y1;y2], 'linestyle', '--');
Any possible method to do it?
  댓글 수: 5
Ghenji
Ghenji 2018년 4월 18일
편집: Ghenji 2018년 4월 18일
char is the main variable/string. call for char is like calling function/some statement that tells that 'sub value' or 'values of sub variable' needs to be taken from these particular main variable. x1,x2,y1,y2 are sub variables. Every main variable contains further 4 sub variables and always in the format x1,x2,y1,y2.
Ghenji
Ghenji 2018년 4월 18일
편집: Ghenji 2018년 4월 18일
Probably this example will help you to understand better --
A = {'Green', 'Magneta'}; %This variable would always contain 2 strings but only one would be used
%%Strings inside should go through data below and get RGB values -
Black = [0,0,0]
Green = [0,255,0]
White = [255,255,255]
Red = [255,0,0]
Lime = [0,255,0]
Blue = [0,0,255]
Yellow = [255,255,0]
Cyan = [0,255,255]
so now with the below function I want the input from only Green as Magneta does not exist in the above data. Magneta shall be ignored.
line(handles.axes [R;G], [G,B]) $takes values only from Green

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

답변 (1개)

Jan
Jan 2018년 4월 17일

A bold guess:

Data = [0, 2.3, 2.3, 2.3; ...
        0, 6.5, 6.5, 6.5; ...
        0, 3.4, 3.4, 3.4; ...
        0, 8.2, 7.5, 8.2; ...
        0, 5.5, 6.5, 5.5];

Now use the index 1 instead of what you call "char1". Then:

index = 1;
x1    = Data(index, 1);
x2    = Data(index, 2);
y1    = Data(index, 3);
y2    = Data(index, 4);

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by