How would I import the data from the fourth row from the following .dat file:
#0 Date-time: 07/06/2011 09:13:53
#1 Recorder: 10T2607
#2 File type: 1
#3 Columns: 3
#4 Channels: 1
#5 Field separation: 0
#6 Decimal point: 0
#7 Date def.: 0 0
#8 Time def.: 0
#9 Channel 1: Temperature(°C) Temp(°C) 3 1
#11 Reconvertion: 0
#19 Line color: 1 2 3 4
#30 Trend Type Number: 1
#33 Limit Temp. Corr. OTCR: 0
1 07.04.11 08:00:00 17,433
2 07.04.11 08:05:00 17,446
3 07.04.11 08:10:00 17,458
4 07.04.11 08:15:00 17,458
So, following the line that begins with #33 I would like to import 17,433 (which should be 17.433) then 17,446 and so on. I have tried to use textscan and headerlines by specifying that the data begins on line 13:
filename = 'Folder\data.dat');
fid = fopen(filename);
data = textscan(fid,'%f\t%f\t%f\t%f\n','Headerlines',13);
fclose(fid);
However, this does not work (in the sense that MATLAB returns an empty array). I guess this is due to the second and third column not being a floating point number, however, it does not work when I specify it to be a string either. What should I try next?
First, note that you have 14 headerlines.
For the data import, you can try the following:
filename = 'Folder\data.dat';
fid = fopen(filename);
data = textscan(fid,'%f\t%s\t%s\t%s','Headerlines',14);
a = cellfun(#(x) str2num(strrep(x, ',', '.')), data{4});
fclose(fid);
This results in
a =
17.4330
17.4460
17.4580
17.4580
Related
I've just installed (uploaded) a new extension onto my Magento2 store, however after compiling and deploying I constantly run into the following error:
1 exception(s):
Exception #0 (Exception): Warning: file_put_contents(/var/www/html/pub/static/frontend/smart_media/smart_media1/th_TH/css/themes.css): failed to open stream: No such file or directory in /var/www/html/vendor/oyejorge/less.php/lessc.inc.php on line 177
Exception #0 (Exception): Warning: file_put_contents(/var/www/html/pub/static/frontend/smart_media/smart_media1/th_TH/css/themes.css): failed to open stream: No such file or directory in /var/www/html/vendor/oyejorge/less.php/lessc.inc.php on line 177
#0 [internal function]: Magento\Framework\App\ErrorHandler->handler(2, 'file_put_conten...', '/var/www/html/v...', 177, Array)
#1 /var/www/html/vendor/oyejorge/less.php/lessc.inc.php(177): file_put_contents('/var/www/html/p...', '/* Less Variabl...')
#2 /var/www/html/app/code/Rokanthemes/Themeoption/Observer/RefreshStyleObserver.php(58): lessc->compileFile('/var/www/html/a...', '/var/www/html/p...')
#3 /var/www/html/vendor/magento/framework/Event/Invoker/InvokerDefault.php(72): Rokanthemes\Themeoption\Observer\RefreshStyleObserver->execute(Object(Magento\Framework\Event\Observer))
#4 /var/www/html/vendor/magento/framework/Event/Invoker/InvokerDefault.php(60): Magento\Framework\Event\Invoker\InvokerDefault->_callObserverMethod(Object(Rokanthemes\Themeoption\Observer\RefreshStyleObserver), Object(Magento\Framework\Event\Observer))
#5 /var/www/html/vendor/magento/framework/Event/Manager.php(66): Magento\Framework\Event\Invoker\InvokerDefault->dispatch(Array, Object(Magento\Framework\Event\Observer))
#6 /var/www/html/generated/code/Magento/Framework/Event/Manager/Proxy.php(95): Magento\Framework\Event\Manager->dispatch('layout_generate...', Array)
#7 /var/www/html/vendor/magento/framework/View/Layout/Builder.php(134): Magento\Framework\Event\Manager\Proxy->dispatch('layout_generate...', Array)
#8 /var/www/html/vendor/magento/framework/View/Page/Builder.php(55): Magento\Framework\View\Layout\Builder->generateLayoutBlocks()
#9 /var/www/html/vendor/magento/framework/View/Layout/Builder.php(65): Magento\Framework\View\Page\Builder->generateLayoutBlocks()
#10 /var/www/html/vendor/magento/framework/View/Layout.php(254): Magento\Framework\View\Layout\Builder->build()
#11 /var/www/html/vendor/magento/framework/View/Layout.php(876): Magento\Framework\View\Layout->build()
#12 /var/www/html/vendor/magento/module-cms/Helper/Page.php(171): Magento\Framework\View\Layout->getBlock('page_content_he...')
#13 /var/www/html/vendor/magento/module-cms/Controller/Index/Index.php(43): Magento\Cms\Helper\Page->prepareResultPage(Object(Magento\Cms\Controller\Index\Index\Interceptor), 'home')
#14 /var/www/html/vendor/magento/framework/App/Action/Action.php(107): Magento\Cms\Controller\Index\Index->execute()
#15 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))
#16 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Cms\Controller\Index\Index\Interceptor->___callParent('dispatch', Array)
#17 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Cms\Controller\Index\Index\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#18 /var/www/html/generated/code/Magento/Cms/Controller/Index/Index/Interceptor.php(26): Magento\Cms\Controller\Index\Index\Interceptor->___callPlugins('dispatch', Array, Array)
#19 /var/www/html/vendor/magento/framework/App/FrontController.php(55): Magento\Cms\Controller\Index\Index\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#20 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#21 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#22 /var/www/html/vendor/magento/module-store/App/FrontController/Plugin/RequestPreprocessor.php(94): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#23 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(135): Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#24 /var/www/html/vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php(73): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#25 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(135): Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#26 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#27 /var/www/html/generated/code/Magento/Framework/App/FrontController/Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)
#28 /var/www/html/vendor/magento/framework/App/Http.php(135): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#29 /var/www/html/vendor/magento/framework/App/Bootstrap.php(256): Magento\Framework\App\Http->launch()
#30 /var/www/html/pub/index.php(37): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))
#31 {main}
I've searched for many solutions, tried to fix permissions, re-deploy static content, remove generated folder, change permissions etc. but to no avail. Some expert insight would be greatly appreciated. Thank you very much
It sounds like potentially the directory target it is trying to write to (smart_media/smart_media1/th_TH/css) does not exist. You may need to modify the extension so that it creates the directory prior to attempting to write to it.
Looks like there are permission issues. You can check magento docs to set the right permissions. You can try these commands
sudo find . -type d -exec chmod 755 {} \;
sudo find . -type f -exec chmod 644 {} \;
i need get matrix from attached text.
this file:
stk.v.11.0
WrittenBy STK_v11.2.0
BEGIN Attitude
NumberOfAttitudePoints 1441
BlockingFactor 20
InterpolationOrder 1
CentralBody Earth
ScenarioEpoch 1 Sep 2019 07:30:00.000000
Epoch in JDate format: 2458727.81250000000000
Epoch in YYDDD format: 19244.31250000000000
Time of first point: 1 Sep 2019 07:30:00.000000000 UTCG = 2458727.81250000000000 JDate = 19244.31250000000000 YYDDD
CoordinateAxes Fixed
AttitudeTimeQuaternions
0.00000000000000e+00 -6.31921733422396e-01 -3.17293118154861e-01 -3.46458799928973e-01 6.16414065342263e-01
6.00000000000000e+01 -6.43812442721383e-01 -3.36172942616126e-01 -3.26612615262581e-01 6.04828480481266e-01
1.20000000000000e+02 -6.55079207620880e-01 -3.54631351046725e-01 -3.06354155948717e-01 5.92667670562959e-01
1.80000000000000e+02 -6.65707851270427e-01 -3.72650894083426e-01 -2.85703135087044e-01 5.79946623834615e-01
i need seprate this 4 row of matrix and asset it to one matrix variable...
in fact i have bigger matrix than that (that near 1400 rows) i must extract from text file and store it in one variable of matrix...
Use readmatrix and specify the number of lines to skip to get to the matrix data. If the number is fixed at 25 as in your example, then:
>> a = readmatrix('textfile.txt','NumHeaderLines',25)
a =
0 -0.6319 -0.3173 -0.3465 0.6164
60.0000 -0.6438 -0.3362 -0.3266 0.6048
120.0000 -0.6551 -0.3546 -0.3064 0.5927
180.0000 -0.6657 -0.3727 -0.2857 0.5799
I'm quite new with Matlab and I've been searching, unsucessfully, for the following issue: I have an unstructure txt file, with several rows I don't need, but there are a number of rows inside that file that have an structured format. I've been researching how to "load" the file to edit it, but cannot find anything.
Since i don't know if I was clear, let me show you the content in the file:
8782 PROJCS["UTM-39",GEOGC.......
1 676135.67755473056 2673731.9365976951 -15 0
2 663999.99999999302 2717629.9999999981 -14.00231124135486 3
3 709999.99999999162 2707679.2185399458 -10 2
4 679972.20003752434 2674637.5679516452 0.070000000000000007 1
5 676124.87132483651 2674327.3183533219 -18.94794942571912 0
6 682614.20527054626 2671000.0000000549 -1.6383425512446661 0
...........
8780 682247.4593014461 2676571.1515358146 0.1541080392180566 0
8781 695426.98657108378 2698111.6168302582 -8.5039945992245904 0
8782 674723.80100125563 2675133.5486935056 -19.920312922947179 0
16997 3 21
1 2147 658 590
2 1855 2529 5623
.........
I'd appreciate if someone can just tell me if there is the possibility to open the file to later load only the rows starting with 1 to the one starting with 8782. First row and all the others are not important.
I know than manually copy and paste to a new file would be a solution, but I'd like to know about the possibility to read the file and edit it for other ideas I have.
Thanks!
% Now lines{i} is the string of the i'th line.
lines = strsplit(fileread('filename'), '\n')
% Now elements{i}{j} is the j'th field of the i'th line.
elements = arrayfun(#(x){strsplit(x{1}, ' ')}, lines)
% Remove the first row:
elements(1) = []
% Take the first several rows:
n_rows = 8782
elements = elements(1:n_rows)
Or if the number of rows you need to take is not fixed, you can replace the last two statements above by:
firsts = arrayfun(#(x)str2num(x{1}{1}), elements)
n_rows = find((firsts(2:end) - firsts(1:end-1)) ~= 1, 1, 'first')
elements = elements(1:n_rows)
Following the articles Concurrency in PowerShell: Multi-threading with Runspaces and Multithreading PowerShell Scripts, I've been experimenting with multithreading using runspaces, and noticed some behavior that I don't understand.
In the script below, the script block $compute_block simulates an expensive computation by sleeping for a second before returning. Ten threads with this computation are spawned, after which the script waits for all of them to complete and prints the results.
The script can be run with either -Case 1 or -Case 2. In case 1, AddScript is called directly with $compute_block. In case 2, an object is created with a method equivalent to $compute_block, and AddScript is given a script block that calls this method.
threading.ps1
Param([Int] $Case)
Set-StrictMode -Version 2
$start_date = Get-Date
Function Get-Timestamp() {
Return ("{0:N3}" -f ((Get-Date) - $start_date).TotalSeconds)
}
Function Write-Timed([String] $str) {
Write-Host "[$(Get-Timestamp)] $str"
}
$count = 10
$runspace_pool = [RunspaceFactory]::CreateRunspacePool(1, $count)
$runspace_pool.Open()
$compute_block = {
Param($x)
Start-Sleep 1
Return $x
}
# Spawn jobs
$jobs = #()
ForEach($i In 0..($count-1)) {
Write-Timed "Creating job #$i"
$ps = [PowerShell]::Create()
Switch($Case) {
1 {
$job = $ps.AddScript($compute_block).AddArgument($i)
}
2 {
$object = New-Object PSObject `
| Add-Member ScriptMethod Compute $compute_block -PassThru
$job = $ps.AddScript({
Param($o, $x)
Return $o.Compute($x)
}).AddArgument($object).AddArgument($i)
}
}
$job.RunspacePool = $runspace_pool
Write-Timed "Starting job #$i"
$result = $job.BeginInvoke()
Write-Timed "Creating record for job #$i"
$record = New-Object PSObject -Property #{
"Job" = $job;
"Result" = $result;
}
Write-Timed "Adding record for job #$i to list"
$jobs += $record
}
# Wait for all jobs to complete
While($true) {
$running_count = #($jobs | Where-Object { -not $_.Result.IsCompleted }).Count
Write-Timed "Waiting for $running_count/$count jobs"
If(0 -eq $running_count) {
Break
}
Start-Sleep 1
}
# Print results
$i = 0
ForEach($job In $jobs) {
$result = $job.Job.EndInvoke($job.Result)
$job.Job.Dispose()
Write-Timed "Job #$i result: $result"
$i++
}
$runspace_pool.Close()
The results are very different (note the timestamps):
Case 1
PS C:\Users\Miranda\Documents> .\threading.ps1 -Case 1
[0.050] Creating job #0
[0.051] Starting job #0
[0.052] Creating record for job #0
[0.052] Adding record for job #0 to list
[0.053] Creating job #1
[0.053] Starting job #1
[0.056] Creating record for job #1
[0.057] Adding record for job #1 to list
[0.057] Creating job #2
[0.058] Starting job #2
[0.061] Creating record for job #2
[0.062] Adding record for job #2 to list
[0.062] Creating job #3
[0.063] Starting job #3
[0.066] Creating record for job #3
[0.066] Adding record for job #3 to list
[0.067] Creating job #4
[0.067] Starting job #4
[0.070] Creating record for job #4
[0.071] Adding record for job #4 to list
[0.071] Creating job #5
[0.072] Starting job #5
[0.075] Creating record for job #5
[0.076] Adding record for job #5 to list
[0.076] Creating job #6
[0.077] Starting job #6
[0.080] Creating record for job #6
[0.080] Adding record for job #6 to list
[0.081] Creating job #7
[0.081] Starting job #7
[0.084] Creating record for job #7
[0.085] Adding record for job #7 to list
[0.085] Creating job #8
[0.086] Starting job #8
[0.102] Creating record for job #8
[0.103] Adding record for job #8 to list
[0.104] Creating job #9
[0.104] Starting job #9
[0.114] Creating record for job #9
[0.115] Adding record for job #9 to list
[0.119] Waiting for 10/10 jobs
[1.120] Waiting for 0/10 jobs
[1.121] Job #0 result: 0
[1.122] Job #1 result: 1
[1.122] Job #2 result: 2
[1.123] Job #3 result: 3
[1.124] Job #4 result: 4
[1.124] Job #5 result: 5
[1.124] Job #6 result: 6
[1.125] Job #7 result: 7
[1.125] Job #8 result: 8
[1.126] Job #9 result: 9
Case 2
PS C:\Users\Miranda\Documents> .\threading.ps1 -Case 2
[0.080] Creating job #0
[0.117] Starting job #0
[0.120] Creating record for job #0
[0.121] Adding record for job #0 to list
[1.126] Creating job #1
[1.128] Starting job #1
[1.129] Creating record for job #1
[2.130] Adding record for job #1 to list
[2.130] Creating job #2
[2.132] Starting job #2
[2.132] Creating record for job #2
[3.134] Adding record for job #2 to list
[3.135] Creating job #3
[3.136] Starting job #3
[3.137] Creating record for job #3
[4.137] Adding record for job #3 to list
[4.138] Creating job #4
[4.139] Starting job #4
[4.140] Creating record for job #4
[5.141] Adding record for job #4 to list
[5.142] Creating job #5
[5.143] Starting job #5
[5.144] Creating record for job #5
[6.144] Adding record for job #5 to list
[6.145] Creating job #6
[6.146] Starting job #6
[6.147] Creating record for job #6
[7.148] Adding record for job #6 to list
[7.149] Creating job #7
[7.150] Starting job #7
[7.151] Creating record for job #7
[8.152] Adding record for job #7 to list
[8.153] Creating job #8
[8.166] Starting job #8
[8.167] Creating record for job #8
[9.168] Adding record for job #8 to list
[9.169] Creating job #9
[9.170] Starting job #9
[9.171] Creating record for job #9
[10.172] Adding record for job #9 to list
[10.192] Waiting for 0/10 jobs
[10.206] Job #0 result: 0
[10.208] Job #1 result: 1
[10.209] Job #2 result: 2
[10.209] Job #3 result: 3
[10.209] Job #4 result: 4
[10.210] Job #5 result: 5
[10.211] Job #6 result: 6
[10.211] Job #7 result: 7
[10.212] Job #8 result: 8
[10.212] Job #9 result: 9
Case 1 behaves as I would expect — the threads are spawned instantaneously, and the script spends a second in the wait loop before finishing.
However, in case 2, all concurrency seems to be lost. Each iteration of the spawning loop blocks until the spawned thread finishes, and once the wait loop is reached, there's nothing left to wait for. Why is this happening?
Edit:
For the record, I'm working with PS 3.0. As noted by Roman Kuzmin, running case 2 in PS 2.0 produces some very strange errors:
PS>.\threading.ps1 -Case 2
[0.060] Creating job #0
[0.060] Starting job #0
The '=' operator failed: Index was outside the bounds of the array..
At C:\Users\Miranda\Documents\threading.ps1:50 char:14
+ $result = <<<< $job.BeginInvoke()
+ CategoryInfo : InvalidOperation: (System.Manageme...hellAsyncResult:PowerShellAsyncResult) [], RuntimeE
xception
+ FullyQualifiedErrorId : OperatorFailed
C:\Users\Miranda\Documents\threading.ps1 : Index was outside the bounds of the array.
At line:1 char:16
+ .\threading.ps1 <<<< -Case 2
+ CategoryInfo : NotSpecified: (:) [threading.ps1], IndexOutOfRangeException
+ FullyQualifiedErrorId : System.IndexOutOfRangeException,threading.ps1
I cannot tell exactly why PowerShell works so but I can tell what causes the
problem and how to work around it. In the case 2 the script block
$compute_block is used as the script method in 10 objects/runspaces - this is
the culprit. If we make and use cloned script blocks, i.e.
$compute_block2 = [scriptblock]::Create($compute_block)
$object = New-Object PSObject `
| Add-Member ScriptMethod Compute $compute_block2 -PassThru
then the problem is resolved.
Interestingly, in PowerShell v2 the original script (case 2) does not work at all, it fails with some weird error messages. With a fix it works in v2, as well as in v3. It looks like you hit a problem case to be avoided. I do not remember such a thing documented. It may be a bug or a feature.
Application crashes in presentFrameBuffer (while running in foreground, no interruption occurring).
It's not crashing in the first frame, it draws for a while then it suddenly crashes.
I don't have exact steps to reproduce, but seems related to drawing something specific, still I have no openGL error reported trough the application, including one error check right before the presentFrameBuffer. If I add glFinish before the presentFrameBuffer will crash in the glFinish.
Application is crashing with EXC_BAD_ACCESS (code=1, address=0x1) and the above callstack without any other error/log/debug info.
Here is the callstack reported at the crash:
Thread 1, Queue : com.apple.main-thread
> #0 0x36871e46 in gpus_ReturnGuiltyForHardwareRestart ()
> #1 0x36872764 in gpusSubmitDataBuffers ()
> #2 0x31eae624 in SubmitPacketsIfAny ()
> #3 0x378a337a in gliPresentViewES ()
> #4 0x325b6df2 in -[EAGLContext presentRenderbuffer:] ()
> #5 0x0052986e in EAGLContext_presentRenderbuffer(EAGLContext*, objc_selector*, unsigned int) ()
> #6 0x000e2a48 in -[EAGLView presentFramebuffer] at /svn/src_svn/GG/iphone/Classes/EAGLView.mm:228
> #7 0x000e4066 in -[GGViewController drawFrame] at /svn/src_svn/GG/iphone/Classes/GGViewController.mm:504
> #8 0x3809ab0a in __NSFireTimer ()
> #9 0x39d36856 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
> #10 0x39d36502 in __CFRunLoopDoTimer ()
> #11 0x39d35176 in __CFRunLoopRun ()
> #12 0x39ca823c in CFRunLoopRunSpecific ()
> #13 0x39ca80c8 in CFRunLoopRunInMode ()
> #14 0x39b9333a in GSEventRunModal ()
> #15 0x3551b288 in UIApplicationMain ()
> #16 0x000e1bae in main at /svn/src_svn/GG/iphone/main.m:14
Anyone has any clue about this one ?
If you are using VAO, this can be caused by the index buffer (element array buffer) referencing vertices beyond the vertex buffer limits (VBO).
Keep in mind that the element array buffer is stored in the VAO, so as long as the VAO is bound, each call to glBindBuffer( GL_ELEMENT_ARRAY_BUFFER ) replaces the index buffer. If you forget to unbind the VAO when you move to your scene's next object you will be altering the VAO of the previous call.
More info over here: http://www.opengl.org/wiki/Vertex_Specification#Index_buffers
And a debugging tip: oversize your vertex buffers, it might turn this crash into a glitch that you can then inspect with the OpenGL ES frame capture tool of XCode (this requires XCode 4.5 and iOS 6).
Looks like the problem was caused by having glEnableClientState(GL_TEXTURE_COORD_ARRAY) for GL_TEXTURE1 but not providing the actual data in the vertex buffer.