2012-05-24 3 views
-1

텍스트 파일에서 데이터를 읽고 MATLAB에서 3D 플롯을 수행하려고합니다. 현재 내가 얻는 것은 빈 플롯이므로 데이터가 올바르게 저장되지 않았거나 전혀 사용되지 않는다고 생각합니다. 또한, 나는 모든 벡터의 끝에 1.000000을 원하지 않으므로 어떻게 무시할 수 있습니까? 감사. 코드Matlab : 파일에서 데이터 저장

인용문

다음
TechEdge4:<152.266724,173.189377,27.995975> 1.000000 
<117.880638,156.116531,27.999983> 1.000000 
<129.849899,59.195660,27.999983> 1.000000 
<249.321121,60.605404,27.999983> 1.000000 
<224.120361,139.072739,28.000668> 1.000000 
<171.188950,143.490921,56.933430> 1.000000 
<171.188950,143.490921,83.548088> 1.000000 
<171.188950,143.490921,27.999985> 1.000000 

됩니다 :

file = fopen('C:\Program Files (x86)\Notepad++\testFile.txt'); % open text file 

tline = fgetl(file); % read line by line and remove new line characters 

% declare empty arrays 
CX = []; 
CY = []; 
CZ = []; 

while ischar(tline) % true if tline is a character array 

    temp = textscan(tline,'%n%n%n', 'delimiter',','); 

    % convert all the cell fields to a matrix 
    CX = vertcat(CX, cell2mat(temp)); 
    CY = vertcat(CY, cell2mat(temp)); 
    CZ = vertcat(CZ, cell2mat(temp)); 

    tline = fgetl(file); 
end 

fclose(file); % close the file 

plot3(CX, CY, CZ) % plot the data and label the axises 
xlabel('x') 
ylabel('y') 
zlabel('z') 
grid on 
axis square 

답변

1

코드는 이제 실행하는 방법, 당신의 temp 변수가 비어 있습니다 여기에

파일입니다 각 반복에서. 그것이 작동되도록해야

CX = vertcat(CX, temp(1)); 
CY = vertcat(CY, temp(2)); 
CZ = vertcat(CZ, temp(3)); 

으로 다음

temp = cell2mat(textscan(tline, '<%n,%n,%n>')); 

와 CX, CY 및 CZ 라인과 textscan 라인을 교체합니다. 물론 TechEdge4가 있기 때문에 첫 번째 라인을 별도로 처리해야합니다.

또한 vertcat 초 전에 임시가 비어 있지 않은지 확인하는 것이 좋습니다.

+0

방금 ​​TechEdge4를 꺼내었지만 코드 줄을 추가하면이 오류가 나타났습니다. 셀이 아닌 배열 개체에서 셀 내용 참조. 44 ==> cell2mat의 오류 cellclass = class (c {1}); 16 ==> 테스트에서 오류가 발생했습니다. CZ = vertcat (CZ, cell2mat (temp)); –

+0

CZ를 완전히 제거하십시오. – Ansari

+0

그러면 Z가없는 3D 그래프를 어떻게 그립니까? –