Excelでの数字の探索

7 views (last 30 days)
健気 大川
健気 大川 on 17 Jun 2021
Commented: 健気 大川 on 17 Jun 2021
前提条件として、B列とD列に次のような数字があります。このときD列の数字によって、C列に0か1を入力したいです。
条件はD列にある数字のC列の行番号は1,それ以外は0にしたいです。書き込む量はB列にある量と同じものです。
(B列の数値に意味はありません)
どなたかお時間がある方助言をお願いいたします。

Accepted Answer

Hernia Baby
Hernia Baby on 17 Jun 2021
D列はindex番号なので、それを加工すればうまくいきます。
xlsreadでは最初の空欄行は除外されます。
なのでblankで除外された数値を補正しています。
clc,clear;
blank = 1; %1行目がブランクのため
[num,~,~] = xlsread('sample.xlsx');
D列目をidxとして保存し、blank分だけ引きます。
その前に、NaNや0行目は存在しないので省きます。
idx = num(:,3);
idx = idx(idx>0)-blank;
num(idx,2) = 1
num = 15×3
0.1000 0 3.0000 0.2000 1.0000 7.0000 0.3000 0 13.0000 0.4000 0 0 0.5000 0 0 0.6000 1.0000 0 0.7000 0 NaN 0.8000 0 NaN 0.9000 0 NaN 1.0000 0 NaN
  1 Comment
健気 大川
健気 大川 on 17 Jun 2021
お忙しい中ありがとうございます。解決いたしました。

Sign in to comment.

More Answers (0)

Categories

Find more on Data Import from MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!