资源简介
matlab开发-stlread。将stl文件读取到matlab补丁兼容的矩阵中。

代码片段和文件信息
function [x y z varargout] = stlread(filename)
% This function reads an STL file in binary format into matrixes X Y and
% Z and C. C is optional and contains color rgb data in 5 bits.
%
% USAGE: [x y z c] = stlread(filename);
%
% To plot use patch(xyzc) or patch(xyz)
%
% Written by Doron Harlev
if nargout>4
error(‘Too many output arguments‘)
end
use_color=(nargout==4);
fid=fopen(filename ‘r‘); %Open the file assumes STL Binary format.
if fid == -1
error(‘File could not be opened check name or path.‘)
end
ftitle=fread(fid80‘uchar=>schar‘); % Read file title
num_facet=fread(fid1‘int32‘); % Read number of Facets
fprintf(‘\ntitle: %s\n‘ char(ftitle‘));
fprintf(‘Num Facets: %d\n‘ num_facet);
% Preallocate memory to save running time
x=zeros(3num_facet); y=zeros(3num_facet); z=zeros(3num_facet);
if use_color
c=uint8(zeros(3num_facet));
end
h = waitbar(0‘Please wait...‘);
for i=1:num_facet
norm=fread(fid3‘float32‘); % normal coordinates ignored for now
ver1=fread(fid3‘float32‘); % vertex 1
ver2=fread(fid3‘float32‘); % vertex 2
ver3=fread(fid3‘float32‘); % vertex 3
col=fread(fid1‘uint16‘); % color bytes
if (bitget(col16)==1 & use_color)
r=bitshift(bitand(2^16-1 col)-10);
g=bitshift(bitand(2^11-1 col)-5);
b=bitand(2^6-1 col);
c(:i)=[r; g; b];
end
x(:i)=[ver1(1); ver2(1); ver3(1)]; % convert to matlab “patch“ compatible format
y(:i)=[ver1(2); ver2(2); ver3(2)];
z(:i)=[ver1(3); ver2(3); ver3(3)];
if mod(ifloor(num_facet/10))==0
waitbar(i/num_faceth);
end
end
if use_color
varargout(1)={c};
end
fclose(fid);
close(h);
% For more information http://rpdrc.ic.polyu.edu.hk/old_files/stl_binary_format.htm
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1840 2018-07-11 20:18 stlread.m
- 上一篇:matlab开发-彩色图像对比度增强
- 下一篇:matlab开发-单相动态电压调节器
相关资源
- matlab开发-能带计算
- matlab开发-FlockingAlgorithm
- matlab开发-MuellerStokesJonesCalculus
- matlab开发-HX711的自定义数据库
- matlab开发-SMOTEBoost
- matlab开发-果蝇优化算法第二版
- matlab开发-多变量决策树
- matlab开发-水轮发电机模型
- matlab开发-交通警告标志识别标签代码
- matlab开发-RUSBoost
- matlab开发-基于遗传算法的机器人运动
- matlab开发-MPU6050加速度陀螺仪
- matlab开发-功率曲线FAsmallscalewindturbi
- matlab开发-NASAJPLDE405开发星历表
- matlab开发-SortinoRatio
- matlab开发-永磁TDC并联电机数学模型
- matlab开发-3相SPWM整流器
- matlab开发-Kilobotswarm控制Matlabarduino
- matlab开发-简单音频播放
- matlab开发-记录文件的绘图仪加速度、
- matlab开发-永磁同步电机PMSM动态数学模
- matlab开发-多目标优化差分进化算法
- matlab开发-随机微分方程解算
- matlab开发-波长调制光谱的二次谐波模
- matlab开发-仿制药生物生理学基础药动
- matlab开发-使用svmrfe选择功能
- matlab开发-KDTreeNearestNeighborandRangeSear
- matlab开发-三维图像堆栈查看器
- matlab开发-动态电压恢复器故障dvr
- matlab开发-数据处理的分组方法GMDH
评论
共有 条评论