


{"id":381352,"date":"2024-09-02T14:51:37","date_gmt":"2024-09-02T14:51:37","guid":{"rendered":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/import-material-txt-file-with-script\/"},"modified":"2024-09-02T14:51:37","modified_gmt":"2024-09-02T14:51:37","slug":"import-material-txt-file-with-script","status":"publish","type":"topic","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/import-material-txt-file-with-script\/","title":{"rendered":"Import material .txt file with script"},"content":{"rendered":"<p>&lt;p&gt;Hello,&lt;\/p&gt;&lt;p&gt;I want to modify my measured material parameters in order to study the effect of perturbations of my measurements on my simulation. &lt;br&gt;To manipulate the data, I use MATLAB and save it as a .txt file. Then I want to import my data via a script from this .txt file. The .txt file is a three-column table with the first column being the wavelength, the second one is the real index, and the third one is the imaginary index. The material is not anisotropic. There is no problem at all with this type of file if I import it manually.&lt;br&gt;&lt;br&gt;If I use the following script, I only use the wavelength and Re{index} column, to import my .txt file:&lt;br&gt;<em>filename = &#8220;test.txt&#8221;; <\/em>&lt;br&gt;<em>sampledData = readdata(filename); <\/em>&lt;br&gt;<em>rows = size(sampledData, 1); <\/em>&lt;br&gt;<em>sampledData_modi = zeros(rows,2); <\/em>&lt;br&gt;<em>sampledData_modi(:,1) = sampledData(:,1);<\/em>&lt;br&gt;<em> sampledData_modi(:,2) = sampledData(:,2);<\/em>&lt;br&gt;<em>test_material = addmaterial(&#8220;Sampled 3D data&#8221;); <\/em>&lt;br&gt;<em>setmaterial(test_material, &#8220;name&#8221;, &#8220;4 Test&#8221;); <\/em>&lt;br&gt;<em>setmaterial(&#8220;4 Test&#8221;, &#8220;sampled data&#8221;, sampledData_modi); <\/em>&lt;br&gt;<em>setmaterial(&#8220;4 Test&#8221;, &#8220;Anisotropy&#8221;, 0);<\/em> &lt;br&gt;I get the correct wavelength imported as well as the correct real part of the refractive index. &lt;br&gt;&lt;br&gt;If I now add one column and populate it with the imaginary part from the .txt file: &lt;br&gt;<em>filename = &#8220;test.txt&#8221;; <\/em>&lt;br&gt;<em>sampledData = readdata(filename); <\/em>&lt;br&gt;<em>rows = size(sampledData, 1); <\/em>&lt;br&gt;<em>sampledData_modi = zeros(rows,3); <\/em>&lt;br&gt;<em>sampledData_modi(:,1) = sampledData(:,1); <\/em>&lt;br&gt;<em>sampledData_modi(:,2) = sampledData(:,2);&nbsp;<\/em>&lt;br&gt;<em> sampledData_modi(:,3) = sampledData(:,3); <\/em>&lt;br&gt;<em>test_material = addmaterial(&#8220;Sampled 3D data&#8221;); <\/em>&lt;br&gt;<em>setmaterial(test_material, &#8220;name&#8221;, &#8220;4 Test&#8221;); <\/em>&lt;br&gt;<em>setmaterial(&#8220;4 Test&#8221;, &#8220;sampled data&#8221;, sampledData_modi); <\/em>&lt;br&gt;<em>setmaterial(&#8220;4 Test&#8221;, &#8220;Anisotropy&#8221;, 0);<\/em>&lt;br&gt;I get the error: <em>the number of columns for the data in &#8216;sampled 3d data&#8217; should be either 2 or 4 <\/em>&lt;br&gt;&lt;br&gt;If I just add one column of zeros: &lt;br&gt;<em>filename = &#8220;test.txt&#8221;; <\/em>&lt;br&gt;<em>sampledData = readdata(filename); <\/em>&lt;br&gt;<em>rows = size(sampledData, 1); <\/em>&lt;br&gt;<em>sampledData_modi = zeros(rows,4); <\/em>&lt;br&gt;<em>sampledData_modi(:,1) = sampledData(:,1); <\/em>&lt;br&gt;<em>sampledData_modi(:,2) = sampledData(:,2);<\/em>&lt;br&gt;<em>sampledData_modi(:,3) = sampledData(:,3); <\/em>&lt;br&gt;<em>test_material = addmaterial(&#8220;Sampled 3D data&#8221;); <\/em>&lt;br&gt;<em>setmaterial(test_material, &#8220;name&#8221;, &#8220;4 Test&#8221;); <\/em>&lt;br&gt;<em>setmaterial(&#8220;4 Test&#8221;, &#8220;sampled data&#8221;, sampledData_modi); <\/em>&lt;br&gt;<em>setmaterial(&#8220;4 Test&#8221;, &#8220;Anisotropy&#8221;, 0); <\/em>&lt;br&gt;The table is not properly imported. &lt;br&gt;&lt;br&gt;Is there a way so solve this issue or work around it?&nbsp;&lt;\/p&gt;&lt;p&gt;Best regards,&nbsp;&lt;br&gt;Tim&lt;\/p&gt;<\/p>\n","protected":false},"template":"","class_list":["post-381352","topic","type-topic","status-publish","hentry","topic-tag-materials","topic-tag-MODE-1","topic-tag-photonics"],"aioseo_notices":[],"acf":[],"custom_fields":[{"0":{"_bbp_subscription":["130711","2592","480237"],"_bbp_author_ip":["2001:6b0:2:2801:b03b:24c8:8c85:1b9a"],"_btv_view_count":["1222"],"_bbp_topic_status":["unanswered"],"_bbp_notification_enabled":["130711","130711","130711","130711","130711","130711"],"_bbp_topic_id":["381352"],"_bbp_forum_id":["27833"],"_bbp_engagement":["2592","130711","480237"],"_bbp_voice_count":["3"],"_bbp_reply_count":["3"],"_bbp_last_reply_id":["397805"],"_bbp_last_active_id":["397805"],"_bbp_last_active_time":["2024-12-17 21:53:38"]},"test":"tim-fuhrmannchalmers-se"}],"_links":{"self":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/381352","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics"}],"about":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/381352\/revisions"}],"wp:attachment":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/media?parent=381352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}